wordpress: 日付アーカイブ(年別・月別・日別)のタイトルを日本語にする
 2012.10.17

wordpress の日付アーカイブのタイトルが day | month | year という並びで表示されます。日本で一般的な日付表示とは異なるのでやや違和感あり。そこで日本仕様に変更します。

以下のphpコードを functions.php に挿入してください。このブログのように 2012年10月17日 という表示になります。

[php]
 function ja_date_wp_title($title, $sep, $seplocation) {
 $year = get_query_var('year');
 $monthnum = get_query_var('monthnum');
 $day = get_query_var('day');
 // from wp-includes/general-template.php:wp_title()
 if ( is_archive() && !empty($year) ) {
 $title = $year . "年";
 if ( !empty($monthnum) )
 $title .= zeroise($monthnum, 2) . "月";
 if ( !empty($day) )
 $title .= zeroise($day, 2) . "日";
 if ($seplocation == 'right') {
 $title = $title . ' ' . $sep . ' ';
 } else {
 $title = $sep . ' ' . $title . ' ';
 }
 }
 return $title;
 }
 add_filter('wp_title', 'ja_date_wp_title', 10, 3);
 [/php]
カテゴリー:wordpress