WordPressの日付別アーカイブのtitleタグが「2012 3月 15」みたいに中途半端な表示になっているのが気になったので調整してみることにしました。
こんな感じのやつね。
修正前
<title> 2012 2月 28</title>
こんな感じで、うまく行くはず。。。
function jp_date_archive_wp_title( $title ) {
$title = trim( $title );
if ( is_date() ) {
$replaces = array(
'/([1-9]{1}[0-9]{3})/' => '$1年',
'/ ([0-9]{1,2}) /' => ' $1日 ',
'/ ([0-9]{1,2})$/' => ' $1日',
'/[\s]+/' => ' '
);
$title = preg_replace( array_keys( $replaces ), $replaces, $title );
}
return $title;
}
add_filter( 'wp_title', 'jp_date_archive_wp_title', 10 );
修正後
<title>2012年 2月 28日</title>
wp_titleのパラメーターでうまくいかない場合があったら、教えてください。







