WordPressで公開日を表示させる方法

ここではWordPressで記事の公開日を表示させる方法について説明していきます。

the_time()

the_time()を用いることで、記事の公開日を表示させることができます。

使用例

<?php
if (have_posts()) :
  while (have_posts()) : the_post();
?>
    公開日:<time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('Y-m-d'); ?></time>
<?php
  endwhile;
endif;
?>

the_time()の引数を指定することで、日付の表示形式を指定しています。

出力結果

まとめ

このように、the_time()を用いることで、公開日を表示させることができます。