我正在尝试根据正在浏览的页面更改徽标。目标是在所有单个产品页面上具有不同的徽标样式。
到目前为止,我的function.php中有什么。我尝试通过is_product()
进行检查,但徽标未更改。
function change_logo_on_single($html) {
if(is_product()){
$html = preg_replace('/<img(.*?)\/>/', '<img src="Black.png" class="custom-logo" alt=logo"" itemprop="logo" />', $html);
}
return $html;
}
add_filter('get_custom_logo','change_logo_on_single');
答案 0 :(得分:1)
您可以使用以下过滤器:
function change_logo_on_single( $html ) {
if ( is_product() )
return '<img src="Black.png" class="custom-logo" alt=logo"" itemprop="logo" />';
return $html;
}
add_filter( 'get_custom_logo', 'change_logo_on_single', 10, 3 );
答案 1 :(得分:1)
您可以为此执行自定义操作
<?php
add_action('my_theme_logo', function(){
if ( is_product() )
return '<img src="singlelogo.png" alt="single-logo" />';
else
return '<img src="main-logo.png" alt=logo"" />';
});
?>
并按照以下定义在主题中使用操作
<?php
echo do_action("my_theme_logo");
?>
答案 2 :(得分:0)
不是在浏览器方面而是在服务器方面吗?您可以使用javascript更改图像的来源。 here对此进行了说明。