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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)