2

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

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

文件结构图

4

1 回答 1

2

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

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

为此,您必须创建一个子主题(或插件)并在您的文件中插入以下内容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 上测试过)

于 2020-01-14T16:05:59.910 回答