目前,我的页面标题由WordPress在调用wp\\u head时处理(我在函数中添加了\\u theme\\u支持(“title tag”)。php)。我想更改类别档案的页面标题格式-目前看起来
<Category name> Archives - <Site name>
我希望他们只是:<Category name> - <Site name>
有没有办法做到这一点?目前,我的页面标题由WordPress在调用wp\\u head时处理(我在函数中添加了\\u theme\\u支持(“title tag”)。php)。我想更改类别档案的页面标题格式-目前看起来
<Category name> Archives - <Site name>
我希望他们只是:<Category name> - <Site name>
有没有办法做到这一点?如果您使用的是Yoast SEO插件(看起来是),那么this 答案可能对你有帮助
如果您使用的是yoast SEO插件,那么最简单的方法就是从“标题和元数据->分类->类别”中删除存档字
查找:
%%term\\u title%%Archives%%page%%%%sep%%%%sitename%%替换为:
%%term\\u标题%%%%%页面%%%%sep%%%%%站点名%%
或者,您可以尝试使用get_the_archive_title
按说明筛选here
add_filter( \'get_the_archive_title\', function ($title) {
if ( is_category() ) {
$title = single_cat_title( \'\', false );
} elseif ( is_tag() ) {
$title = single_tag_title( \'\', false );
} elseif ( is_author() ) {
$title = \'<span class="vcard">\' . get_the_author() . \'</span>\' ;
}
return $title;
});
您需要使用wp\\u标题挂钩,请尝试以下代码它应该适合您:
add_filter( \'wp_title\', \'my_new_category_title\', 10, 2 ); function my_new_category_title($title) { if (is_category() || is_archive()) { $title = \' - \'.get_bloginfo(\'name\').\' \'.$title; } return $title; }
如果只想编辑标题标记(),而不想编辑页面顶部的内容,可以执行以下操作:
// define the document_title_parts callback
function filter_document_title_parts( $title ) {
if( is_category() ){
$title[title] = str_replace( \'Archives\', \'\', $title[title] );
}
return $title;
};
// add the filter
add_filter( \'document_title_parts\', \'filter_document_title_parts\', 10, 1 );
此外,您还可以更改默认值Category Title
不使用SEO插件,通过重写默认过滤器使用函数single_cat_title
具体如下:
/**
* Add Custom Category Title
*/
add_filter( \'single_cat_title\', \'custom_category_title\', 10, 2 );
function custom_category_title( $title ) {
if ( is_category() || is_archive() ) {
$title = $title . \' Example\';
}
return $title;
}
上述代码的输出为:类别示例
我有大约2000本书。如何自动删除具有这些标题的帖子?例如