Wordpress 移除 archive_title 自带前缀文字

Wordpress 函数 the_archive_title() 输出的标题自带“分类:”、“标签:”、“作者:”等前缀,如果要移除,只要在 function.php 文件里添加以下代码即可。

add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );

如果是要针对性的移除,则可以按下面的写法:

add_filter( 'get_the_archive_title', function ( $title ) {
    if( is_category() ) { //移除分类:
        $title = single_cat_title( '', false );
    }
    if ( is_author() ) { //移除作者:
        $title = get_the_author();
    }
    if ( is_post_type_archive() ) { //移除自定义文章类型:
        $title = post_type_archive_title( '', false );
   }
    return $title;
});

根据需要删除或者添加if代码即可。

换色
阅读
登录
扫码