【问题标题】:Change my custom logo link Wordpress更改我的自定义徽标链接 Wordpress
【发布时间】:2016-08-03 15:58:30
【问题描述】:

我正在尝试将我的 Wordpress 徽标链接更改为自定义链接。

假设我要设置的新链接是http://newlink.html

我正在使用带有 25 个主题的 wordpress 4.5.3。 (所以我在 Stack 上找到的最后一个答案已经过时,因为自定义徽标在 4.5 中发生了变化)。

我进入header.php发现:

twentyfifteen_the_custom_logo();

    if ( is_front_page() && is_home() ) : ?>
        <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" 
            rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    <?php else : ?>
        <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" 
            rel="home"><?php bloginfo( 'name' ); ?></a></p>
    <?php endif;

所以如果我理解正确,我会为我的自定义徽标调用函数twentyfifteen_the_custom_logo();,接下来的两个链接不会影响我,因为它们是如果我仍在使用文本徽标,我没有。

然后我去寻找这个twentyfifteen_the_custom_logo(); 并找到了一些我可以更改的参数:

function.php

/*
 * Enable support for custom logo.
 *
 * @since Twenty Fifteen 1.5
 */
add_theme_support( 'custom-logo', array(
    'height'      => 248,
    'width'       => 248,
    'flex-height' => true,
) );

所以我有了添加类似'src' =&gt; http://newlink.html, 的想法,但documentation 看起来不像接受这个参数。

我继续寻找功能并到达template-tags.php并找到:

if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) :
/**
 * Displays the optional custom logo.
 *
 * Does nothing if the custom logo is not available.
 *
 * @since Twenty Fifteen 1.5
 */
function twentyfifteen_the_custom_logo() {
    if ( function_exists( 'the_custom_logo' ) ) {
        the_custom_logo();
    }
}
endif;

这个函数调用了我在任何地方都找不到的the_custom_logo();

我可能错过了一些东西,或者我看起来不正确,如果你能帮助我找到如何将我的自定义徽标链接更改为我的自定义 url,那就太好了 :)

谢谢!

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    添加 WordPress 过滤器以更改自定义徽标链接。

    添加您的functions.php 文件。

    http://screencast.com/t/z19OejeBK

    add_filter( 'get_custom_logo', 'wecodeart_com' );
    function wecodeart_com() {
        $custom_logo_id = get_theme_mod( 'custom_logo' );
        $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
                esc_url( 'www.google.com' ),
                wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                    'class'    => 'custom-logo',
                ) )
            );
        return $html;   
    } 
    

    【讨论】:

    • 登录徽标链接更改使用此:function login_url() { return home_url(); } add_filter( 'login_headerurl', 'login_url' );
    猜你喜欢
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多