2016-10-02 46 views
1

在我的WooCommerce網絡商店中,我想從產品類別檔案頁面的主標題中刪除Archive of :刪除產品類別檔案頁面主標題中的一些文字

下面是截圖: screenshot

我曾嘗試使用基於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 :標題?

謝謝。

回答

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

相關問題