1

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.

4

1 回答 1

1

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

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

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 文件中或任何插件文件中。

于 2016-10-02T09:07:23.463 回答