正文:
在WordPress上,对文章进行分类和贴标签是非常常见的优化方法。如果使用漂亮的固定链接地址形式,分类和标签页面的URL中会包含/category/和/tag/字符串。标签的URL相对较短,只有3个字符。然而,分类的URL就不那么美观了。因此,许多人希望能够去掉分类链接中的”category”字样。这样做有利有弊,需要仔细权衡。
要实现说的去掉页面的 “分类:”和“标签:”,可以使用下面的代码,将该代码添加到当前使用的主题的 functions.php 文件即可。
代码如下:
//移除页面分类和标签字样
function my_theme_archive_title( $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>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
转载请注明:汇站网 » (WordPress教程)移除页面上的分类和标签标识