LoginSignup
0
0

More than 3 years have passed since last update.

WordPressのAll in One SEOパックで指定されたTDKを変更したい!

Last updated at Posted at 2020-12-07

前提

WordPress
All in One SEOパックインストール済み

背景

今回関わっている案件で顧客からWordPressの記事サイトのTDKをカスタマイズしたいという要望を受けて対応をしたので、そのあたりについてメモがてらまとめておく
All in One SEOパックを利用しているので、ある程度は設定画面からカスタマイズできるのはこの記事に辿りつくかたならご存知だと思いますが、今回特定のカテゴリのみカスタマイズしたいという要望だったため、設定画面からでの対応では難しく、モジュール側に手を入れる方向で対応を行いました

対応内容

結論から言うと専用のfilterがあったので、functions.phpにそのフィルターを追加する形で対応を行いました。ソースコードは以下

functions.php
/**
 * 一覧のdescription制御
 * @param $description All in One SEOで設定しているdescription
 */
function archive_description_custom($description) {
    if (is_archive()) {
        // 表示中のカテゴリを取得
        $cat = get_term(get_query_var('cat'), 'category');
        // カテゴリの判定ロジック
        if ($cat->slug === 'XXXXXXXX') {
            // ここで変更したい内容のdescriptionを入れる
            $description = "";
        }
    }
    // カスタマイズ後のディスクリプションをreturnする
    return $description;
}
add_filter('aioseop_description', 'archive_description_custom');

aioseop_xxxxの部分をtitleに変更すればそのままtitleのカスタマイズができます

0
0
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
0