WordPress Wednesday: Using the_date() vs. the_time()

Geek Factor: 2

In this week’s WordPress Wednesday, we’re going to cover the difference between WP’s the_date() and the_time() template tags.

As a default, most WordPress themes will use the_date() with each post, to display when the post was written.

At Stem, when we use WordPress as a CMS, we often use the posts as news items. However, when two posts are published on the same day — say, May 9th — when the_date() tag is used, only one date will appear:

WordPress’s the_date() tag will only display once for each date; when there are multiple posts on the same day, the date on only the most recent one will appear. This one-date-a-day set-up works fine for blogs, where the vistor reads top to bottom, but can be confusing or look broken in other scenarios.

By using the_time() tag rather than the_date(), each instance of a date will appear:

Both tags — the_time() and the_date() — use the sameĀ dateĀ formatting. This means if you switch from one to the other in your theme, you can still keep the same formatting code. You can also use the following code to use the Date Format set in the admin dashboard under Settings > General Settings for either tag:

<?php the_time(get_option('date_format')); ?>

Have you had any surprises with how WordPress template tags actually work? Please share them in the comments!

Leave a Comment

Note: Fields marked with a * are required; email addresses are not published.

Legal FAQ Collections