WordPressで記事の公開日や更新日を取得
日付を取得できる関数
| <?php the_time(); ?> | 投稿の公開日の出力 |
| <?php get_the_time(); ?> | 投稿の公開日の取得 <?php get_the_time(‘Y年m月d日’); ?> ※ 特定の投稿の日付を取得する場合(ID:30)<?php get_the_time(‘Y年m月d日’ , 30 ); ?> |
| <?php the_modified_time(); ?> | 投稿の最終更新日の出力 |
| <?php get_the_modified_time(); ?> | 投稿の最終更新日付の取得 <?php the_modified_date(‘Y年m月d日’); ?> |
日付のフォーマット
公開日が2025年6月18日の場合
| <?php get_the_time(‘Y年m月d日’); ?> | 出力結果:2025年6月18日 |
<?php get_the_time(‘Y/m/d‘); ?> | 出力結果:2025/6/18 |
<?php get_the_time(‘Y.m.d‘); ?> | 出力結果:2025.6.18 |
コピーライトの年号を自動更新する
今年の年数(4桁)を出力する場合
<p>© <?php the_date('Y');?> Site Name.</p>
WorePressのテーマカスタマイズ時によく使う基本的なタグをまとめた、こちらの記事もどうぞ
