【WP】timeタグを使って投稿日や更新日を表示する方法

WordPressでtimeタグを使って投稿日や更新日を表示する方法についてまとめました。
投稿日を表示する
datetime属性もしくは<time></time>内に既定の書式で取得し表示ます
|
1 2 3 |
<time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('Y/m/d'); ?></time> <time><?php the_time('Y-m-d'); ?></time> |
間違った書き方
|
1 |
<time><?php the_time('Y/m/d'); ?></time> |
datetime属性を省略する場合は、<time>~</time>の間を独自の形式で記述してはいけません。
更新日を表示する
|
1 2 3 |
<time datetime="<?php the_modified_time('Y-m-d'); ?>"><?php the_modified_time('Y/m/d'); ?></time> <time><?php the_modified_time('Y-m-d'); ?></time> |
間違った書き方
|
1 |
<time><?php the_modified_time('Y/m/d'); ?></time> |
datetime属性を省略する場合は、<time>~</time>の間を独自の形式で記述してはいけません。
![MARKLEAPS[マークリープス]](https://markleaps.com/blog/wp-content/themes/mkl/images/00_logo.png)

![[WordPress] CSVで記事を一括インポート-プラグイン「WP ALL Import」の使い方](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import-500x254.jpg)
![[WordPress] 記事への画像挿入方法](https://markleaps.com/blog/wp-content/uploads/2025/10/pic_manual_mainimg-500x254.png)
![[WordPress] カテゴリーとタグの違いと設定方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-category-tag-500x254.jpg)
![[WordPress] 挙動確認付き!大画像自動リサイズ(-scaled)と srcset属性 の自動付与](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-scaled-srcset-500x254.jpg)