去掉 wordpress 分类页标题中的“分类”字样

更新日期: 2018-07-11 阅读次数: 9874 分类: wordpress

grep 发现 archive.php 代码中包含

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

the_archive_title 是 wordpress 内置函数,无法直接修改。

the_archive_title( string $before = '', string $after = '' )

Display the archive title based on the queried object.

解决方法

在 functions.php 中添加

add_filter( 'get_the_archive_title', function ( $title ) {
    if( is_category() ) {
        $title = single_cat_title( '', false );
    }

    return $title;
});

参考

http://doc.weixiaoduo.com/wordpress/3827.html

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式