gpt4 book ai didi

html - 如何仅更改带有 oceanWP 主题的 wordpress 网站上 Logo 的主页 url?

转载 作者:行者123 更新时间:2023-12-04 10:45:21 36 4
gpt4 key购买 nike

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

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

File structure image

最佳答案

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

您可以使用 get_custom_logo 钩子(Hook)修改自定义 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 上测试过)

关于html - 如何仅更改带有 oceanWP 主题的 wordpress 网站上 Logo 的主页 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731400/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com