dongxian6715 2016-11-17 03:31
浏览 35
已采纳

有问题修改主题代码以替换徽标URL

Using WordPress on the default twentysixteen theme. This is a code issue not a theme issue which is why I'm posting it on SO. I have a feeling I'm just doing something simple wrong but I've searched and figured out what code I need to change but it seems like it's not making the changes as expected.

So what I'd like to do is change the LOGO that is currently going to the website "home". I'm talking about the front end logo at the top left that i'd like to go to one of my other sites which has more relevant information.

But when I change this code:

        <div class="header-image">
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                <img src="<?php header_image(); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_custom_header()->attachment_id ) ); ?>" sizes="<?php echo esc_attr( $custom_header_sizes ); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
            </a>

To:

        <div class="header-image">
            <a href="http://external-website-here.com">
                <img src="<?php header_image(); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_custom_header()->attachment_id ) ); ?>" sizes="<?php echo esc_attr( $custom_header_sizes ); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
            </a>

It doesn't seem to be affecting where I'm redirected when clicking on the logo image. In other words it still goes to the home_url it seems instead of the external site.

Any suggestions are much appreciated.

Additional Information: No caching is enabled, tried other browser/devices to make sure it's not a cache issue.

Update: Even remove the entire code from my first code box it doesn't change anything on the front end. Maybe I'm modifying the wrong file? How do I figure out what file the logo code is living in?

  • 写回答

1条回答 默认 最新

  • douyu9159 2016-11-17 19:31
    关注

    You're looking at the wrong code.

    You need to edit line 35 and 37 of the header.php, which I can see here: https://github.com/WordPress/twentysixteen/blob/master/header.php

    This is because you don't have a logo, as far as I can tell anyway.

    Update:

    I've updated your site to work.

    What I did was add function to filter the home url;

    //functions.php (end of file)
    /**
     * Changes the url returned from home_url();
     */
    function change_home_link($url, $path, $orig_scheme, $blog_id){
        return 'http://google.com';
    }
    

    Then add and remove the filter in the header

    //header.php line 32
    add_filter( 'home_url', 'change_home_link' );
    twentysixteen_the_custom_logo();
    remove_filter( 'home_url', 'change_home_link' );
    

    You could also just remove the twentysixteen_the_custom_logo() function and replace it with what ever you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题