
本文详解如何让 WordPress 的 the_custom_logo() 函数在首页也保持可点击并跳转至首页,解决因主题启用 'unlink-homepage-logo' => true 导致的链接被移除问题。
本文详解如何让 wordpress 的 `the_custom_logo()` 函数在首页也保持可点击并跳转至首页,解决因主题启用 `'unlink-homepage-logo' => true` 导致的链接被移除问题。
在基于 Twenty Twenty-One 或其子主题(如 twentytwentyone-child)开发时,你可能会发现:尽管调用了 the_custom_logo(),但当用户访问网站首页时,Logo 图片不再包裹 @#@#@#@#@#@#@#@#@#@0):
// 在子主题的 functions.php 中添加以下代码
function child_theme_setup_custom_logo() {
// 先移除父主题已注册的 custom-logo 支持
remove_theme_support('custom-logo');
// 重新注册,关键:设置 'unlink-homepage-logo' => false
$logo_width = 300;
$logo_height = 100;
add_theme_support('custom-logo', array(
'height' => $logo_height,
'width' => $logo_width,
'flex-width' => true,
'flex-height' => true,
'unlink-homepage-logo' => false, // ? 核心修复项:强制首页保留链接
));
}
add_action('after_setup_theme', 'child_theme_setup_custom_logo', 9);
至此,无论用户处于首页还是内页,点击 Logo 均可一致跳转至网站首页,实现专业、统一的导航体验。

<div class="site-logo">
<a href="https://yoursite.com/" class="custom-logo-link" rel="home">
@@##@@
</a>
</div>











