变化的标志取决于页面

问题描述 投票:0回答:3

我想改变这取决于我在浏览网页的标志。我们的目标是让所有的单品页面上的不同标志风格。

我在我的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');
php wordpress
3个回答
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");
?>


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

0
投票

是不是东西,而在浏览器的一侧上比在服务器的?你可以使用JavaScript来改变图像的来源。怎么办呢描述here

© www.soinside.com 2019 - 2024. All rights reserved.