制作備忘録

仕事でぶちあたった壁の備忘録です。Wordpressが多め。

All in One SEO でカスタム投稿詳細の<title>タグが正常に出力されない

カスタム投稿の詳細記事でアーカイブのタイトルが自動生成されてしまう問題が発生したので、
強制的に以下のような対応をした。

functions.php

カスタム投稿が special の場合

//titleタグをオフ
add_filter( 'aioseo_disable_title_rewrites', 'aioseo_disable_term_title_rewrites' );
function aioseo_disable_term_title_rewrites( $disabled ) {
  if ( is_singular('special') ) { 
    return true;
  }
  return false;
}
header.php で独自に

All in One SEO でタイトルを書き換えている場合は、All in One SEO のタイトルを取得して表示する

<?php
        if ( is_singular('special') ) { 
            $my_title = get_post_custom()['_aioseo_title'][0];
            if($my_title=='') {
    ?>
    <title><?php the_title() ?> | <?php bloginfo ( 'name' ); ?></title>
    <?php } else { ?>
    <title><?php echo $my_title ?></title>

    <?php
            }
        } 
    ?>
参考サイト

dubdesign.net