問題描述

我的主題的 archive.php 中有以下代碼:

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

這給我的標題像 「類別:俄羅斯」,「標籤:美國」,「作者:約翰」 。

我想刪除”Category:”,”Tag:” 和”Author:” 部分,只顯示類別,標籤和作者姓名。

有誰知道如何完成這個?

謝謝。

最佳解決方案

您可以擴展我在 this answer 中提到的 get_the_archive_title 過濾器

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;

});

次佳解決方案

使用功能 single_term_title()

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。