深度阅读

wordpress删除the_archive_title中的 "Category:", "Tag:", "Author:" 等

作者
作者
2023年08月22日
更新时间
9.08 分钟
阅读时间
0
阅读量

原本展示

<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>

方案1
You can extend the get_the_archive_title filter which I’ve mentioned in this answer

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>';
    } elseif (is_tax()) { //for custom post types
        $title = sprintf(__('%1$s'), single_term_title('', false));
    } elseif (is_post_type_archive()) {
        $title = post_type_archive_title('', false);
    }
    return $title;
});

还有个简单的方案,直接使用single_term_title输出即可

single_term_title()

参考链接
https://wordpress.stackexchange.com/questions/179585/remove-category-tag-author-from-the-archive-title

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。