【问题标题】:Removing some text in main title on product category archives pages删除产品类别档案页面主标题中的一些文本
【发布时间】:2023-03-12 16:36:01
【问题描述】:

在我的 WooCommerce 网上商店,我想从产品类别档案页面的主标题中删除 Archive of :

这是一个截图:

我已经尝试使用这个基于on this answer的代码, 但它不起作用

function changing_category_archive_page_title( $page_title ) {
    if(is_product_category()) {
        $title_arr = explode(' :', $page_title);
        $new_title = $title_arr[2];
        if(!empty($new_title)) echo $new_title;
        else echo $page_title;
    }
}
add_filter( 'woocommerce_page_title', 'changing_category_archive_page_title', 10, 1 );

如何从标题中删除 Archive of :

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce categories hook-woocommerce


    【解决方案1】:

    'Archive of : ' 文本似乎是您的主题的自定义,因为它在经典 WooCommerce 中不存在。所以在这种情况下,你使用的代码不起作用是正常的。

    没有任何保证,因为我自己无法测试,你应该尝试使用WordPress gettex() function,因为我认为这是对主标题的补充,就像某些主题所做的那样:

    add_filter( 'gettext', 'removing_specific_text_in_categories_page_titles', 10, 2 );
    function removing_specific_text_in_categories_page_titles( $translated_text, $untranslated_text )
    {
        if ( 'Archive of :' == $untranslated_text ) {
            $translated_text = '';
        }
        return $translated_text;
    }
    

    此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2018-12-11
      • 2019-01-06
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多