首页 文章

删除产品类别归档页面上主 Headers 中的某些文本

提问于
浏览
1

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

这是截图:
screenshot

我试过使用这个基于on this answerBut it doesn’t work 的代码:

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

如何从 Headers 中删除 Archive of :

谢谢 .

1 回答

  • 1

    看起来这个'Archive of:'文本是您主题的自定义,因为它在经典的WooCommerce中不存在 . 因此,在这种情况下,您正在使用的代码不起作用是正常的 .

    没有任何保证,因为我不能自己测试它,你应该尝试使用WordPress gettex() function,因为我认为这是主 Headers 的补充,正如一些主题用来做:

    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文件中,或者也可以放在任何插件文件中 .

相关问题