如何在具有海洋WP主题的wordpress网站上仅更改徽标的主页URL?



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

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

文件结构图像

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

如果你还需要处理诸如徽标alt属性为空或徽标未设置之类的事情,则可以参考get_custom_logo()函数。

(我已经在WordPress 5.3.2和OceanWP 1.7.4上测试过它(

最新更新