WordPressのテーマ「TwentyFifteen」では、記事の末尾に投稿日が表示されます。
これを投稿日ではなく、更新日にする方法を紹介します。
1. ファイルを開く
TwentyFifteenでは、投稿ページのメタ情報(日付や著者など)はtemplate-tags.php
で定義されています。
ファイルの場所は通常、以下のディレクトリにあります。
/wp-content/themes/twentyfifteen/inc/template-tags.php
2. 更新日の関数を探す
template-tags.php
内の80行目あたりにある、投稿日を出力する関数をコメントアウト(もしくは削除)し、更新日が表示されるように変更します。
$time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), get_the_date(), esc_attr( get_the_modified_date( 'c' ) ), get_the_modified_date() );
このコードを、下記のように編集します。
$time_string = sprintf( // $time_string, // esc_attr( get_the_date( 'c' ) ), // get_the_date(), esc_attr( get_the_modified_date( 'Y年m月d日' ) ), get_the_modified_date() );
行頭にスラッシュを2つ入力する事で、コメントアウト(コードの無効化)を行います。
これで記事には投稿日ではなく、更新日が表示されるようになります。
関連記事