記事を書いたら、それで終わりってわけじゃなく、見直して付け足したりメンテナンスしていくことになるので、最終更新日を表示するようにしてみようと思います。
プラグインでパパっと出来ればいいんですが、無理そうなので、PHPの該当部分を修正することにしました。
そもそもまず、どの部分を修正したらいいのか分からなかったので、探してみたところ以下の部分のようでした。
WordPress管理画面の左メニュー→「外観」→「テーマの編集」→「テーマファイル」→「template-parts」→「post」→「content.php」の「twentyseventeen_time_link()」という関数。
関数化されているので、content.phpの中身を修正しても修正されるのはcontent.phpを使っているところだけということになります。
なので、「twentyseventeen_time_link()」関数自体を修正することにします。関数自体を修正してやると、その関数が呼び出されている全ての箇所を修正できることになります。
どこにその関数があるのか探してみると、以下ファイルにありました。
WordPress管理画面の左メニュー→「外観」→「テーマの編集」→「テーマファイル」→「inc」→「template-tags.php」
以下ソースコードをコメントアウトします。
1 2 3 4 5 6 7 8 9 10 11 | // $time_string = '"<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; // if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { // $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; // } // // $time_string = sprintf( $time_string, // get_the_date( DATE_W3C ), // get_the_date('Y年n月j日'), // get_the_modified_date( DATE_W3C ), // get_the_modified_date('Y年n月j日') // ); |
以下のソースコードへ置き換えます。
1 2 3 4 5 6 7 | $time_string = '<time class="entry-date published" datetime="%1$s">公開日: %2$s / 最終更新日: %3$s</time><time class="updated" datetime="%4$s"></time>'; $time_string = sprintf( $time_string, get_the_date( DATE_W3C ), get_the_date('Y年n月j日'), get_the_modified_date('Y年n月j日'), get_the_modified_date( DATE_W3C ) ); |
コメントアウトしたソースコードを見てみると、最終更新日の情報を取得して表示しているように見えるんですが、上手く表示されないので、力技になってしまってる気がします。。。
この状態で同じページを見てみると・・・
上手く最終更新日を表示できるようになってます。
おー、いい感じです。