删除产品类别档案页面主标题中的一些文字
问题描述:
在我的WooCommerce网络商店中,我想从产品类别档案页面的主标题中删除Archive of :
。删除产品类别档案页面主标题中的一些文字
我曾尝试使用基于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 :
标题?
谢谢。
答
这似乎是这个
'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文件或任何插件文件中。