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

时间:2016-11-17 03:31:05

标签: php wordpress

在默认的二十九主题上使用WordPress。这是一个代码问题,而不是主题问题,这就是我在SO上发布它的原因。我有一种感觉,我只是做了一些简单的错误,但我已经搜索过并想出了我需要改变的代码,但似乎没有按预期进行更改。

所以我想做的就是更改当前进入网站" home"的LOGO。我正在谈论左上角的前端徽标,我想去其他一个有更多相关信息的网站。

但是当我更改此代码时:

        <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>

致:

        <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>

在点击徽标图片时,我似乎没有影响我重定向的位置。换句话说,它似乎仍然是home_url而不是外部站点。

非常感谢任何建议。

其他信息:未启用缓存,尝试使用其他浏览器/设备以确保其不是缓存问题。

更新:即使从我的第一个代码框中删除整个代码,它也不会改变前端的任何内容。也许我正在修改错误的文件?如何确定徽标代码所在的文件?

1 个答案:

答案 0 :(得分:1)

您正在查看错误的代码。

您需要编辑header.php的第35行和第37行,我可以在此处看到:https://github.com/WordPress/twentysixteen/blob/master/header.php

这是因为我无论如何都没有徽标。

<强>更新

我已将您的网站更新为工作。

我所做的是添加功能来过滤主页;

//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';
}

然后在标题

中添加和删除过滤器
//header.php line 32
add_filter( 'home_url', 'change_home_link' );
twentysixteen_the_custom_logo();
remove_filter( 'home_url', 'change_home_link' );

您也可以删除twentysixteen_the_custom_logo()功能并将其替换为您想要的功能。