投稿の最終更新日を表示する
投稿の最終更新日を表示する場合は、the_modified_date()
を使います。
最終更新日:<?php the_modified_date(); ?>
出力結果は「最終更新日:2025/02/20」となります(日付のフォーマットはパラメータで指定されていないため、管理画面の設定が適用されます)。
時刻まで表示する場合は、パラメータで時刻を含むフォーマットを指定します。取得する場合も同様です。
最終更新日:<?php the_modified_date('Y/m/d H:i:s'); ?>
投稿の最終更新日を取得する
投稿の最終更新日を取得する場合は、get_the_modified_date()
を使います。
<?php $modified_date = get_the_modified_date(); ?>
投稿の公開日と比較する
投稿の公開日と比較して、公開日以降に更新していた場合に最終更新日を表示する場合は以下のように書きます。
<?php if(get_the_modified_date('Y-m-d') !== get_the_date('Y-m-d')): ?>
最終更新日:<?php the_modified_date(); ?>
<?php endif; ?>