LoginSignup
0
1

More than 3 years have passed since last update.

WordPress「the_archive_title」使用時に余分な「タグ:」等を消す方法

Posted at

the_archive_titleを使えば
WordPressで設定している「タグ」、「年月などアーカイブ」等々、簡単に出力できる。

はじめに、「the_archive_title」の使用方法は簡単でこうする。

php
<h1><?php the_archive_title(); ?></h1>

めっちゃ便利!!

余分な「タグ:」等を消す方法

「function.php」に下記のコード書くだけ。

function.php
/* ---------------------------------------
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_tax()) {
        $title = single_term_title('',false);
    } elseif (is_post_type_archive() ){
        $title = post_type_archive_title('',false);
    } elseif (is_date()) {
        $title = get_the_time('Y年n月');
    } elseif (is_search()) {
        $title = '検索結果:'.esc_html( get_search_query(false) );
    } elseif (is_404()) {
        $title = '404ページ';
    } else {
    }
    return $title;
});

さいご

以上!!
では、また!!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1