【问题标题】:How do I change only the home url of logo on a wordpress site with oceanWP theme?如何仅更改带有 oceanWP 主题的 wordpress 网站上徽标的主页 url?
【发布时间】:2020-01-14 10:01:20
【问题描述】:

我在 abc.com 上部署了一个站点,它使用 angular 作为主页,使用 WordPress 作为博客。我已将 WordPress 网站部署在 abc.com 内的子文件夹中。文件结构如下图所示。

现在我只想更改 WordPress 网站徽标上的主页链接,单击该链接会将我们重定向到 abc.com。其余博客链接将正常工作,例如“abc.com/myProj/blog-detail”

File structure image

【问题讨论】:

    标签: html angular wordpress tags website-homepage


    【解决方案1】:

    OceanWP 使用 the_custom_logo() 函数显示您的自定义徽标并链接到 WordPress 网站的主页 (example.com/myProj)。呈现徽标的文件位于/wp-content/themes/oceanwp/partials/header/logo.php

    您可以使用get_custom_logo 挂钩修改自定义徽标的HTML,并将链接更改为指向实际主页(example.com)。

    为此,您必须创建一个 child theme(或插件)并将以下内容插入到您的 functions.php 文件中:

    <?php
    /**
     * Modify the logo link
     *
     * @param string $html  Custom logo HTML output
     * @param int $blog_id  ID of the blog to get the custom logo for
     * @return string       Custom logo HTML output with modified link
     */
    function oceanwp_child_modify_logo_link( $html, $blog_id ) {
      $custom_logo_id = get_theme_mod( 'custom_logo' );
      $html = sprintf(
        '<a href="%1$s" class="custom-logo-link" rel="home">%2$s</a>',
        esc_url( 'https://example.com/' ),  // modify the link here
        wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
      );
    
      return $html;
    }
    
    add_filter( 'get_custom_logo', 'oceanwp_child_modify_logo_link', 10, 2 );
    

    如果还需要处理 logo alt 属性为空或 logo 未设置等问题,可以参考get_custom_logo() 函数。

    (我在 WordPress 5.3.2 和 OceanWP 1.7.4 上测试过)

    【讨论】:

    • 我在子主题的functions.php中添加了代码,保存文件后代码在几秒钟后消失了! wordpress 中的这个 bug 是什么?
    • 这不适用于我的海洋 wp 主题。我在子主题的 function.php 中保存的任何内容在保存片刻后都消失了。我必须创建一个自定义标题并手动添加到徽标的链接。感谢您的帮助!
    猜你喜欢
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2017-03-10
    • 2021-02-10
    • 2020-08-27
    • 1970-01-01
    相关资源
    最近更新 更多