dououde4065
2016-10-02 08:51 阅读 17
已采纳

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

On my WooCommerce web shop, I would like to remove Archive of : from main title on product category archives pages.

Here is a screenshot: screenshot

I have tried to use this code based on this answer, But 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 );

How can I do to remove Archive of : from title?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanpengya7074 duanpengya7074 2016-10-02 09:07

    It seem that this 'Archive of : ' text is a customization of your theme, as it doesn't exist in classic WooCommerce. So in this case, it's normal that the code you are using doesn't work.

    Without any guaranty, as I can't test it my self, you should try to use the WordPress gettex() function, as I think that this is an addition to main title, as some themes use to do:

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

    This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    点赞 评论 复制链接分享

相关推荐