When it comes to displaying the date on blog posts, many WordPress themes – not all, but many – opt to display the date on the most recent post of the day, and then simply display the title and the content for the rest of the posts throughout the day.

This results in the content feed looking something like this:

But not everyone likes that. Luckily, there is an easy fix for this.

Show The Date on Every Post

When it comes to displaying the date, WordPress offers two functions for doing so:

If you end up using the_date, then you’re going to end up seeing the results mentioned above. Simply put, using the_date results in WordPress displaying the date once per day regardless of the number of posts for that day.

On the other hand, using the_time will unconditionally displaying when the post was published. In order to show the date on every post in WordPress, look for the call that looks something like this:

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

Then replace it with this:

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

And that should take care of it.

Why Does It Work This Way?

First, recall that WordPress offers two different fields for the date and the time on the General page in the Settings section of options.

Note that each of these fields uses PHP conventions for formatting the date and the time. This means that if you were to pass the the_time something like ‘F j, Y’ it would actually just display the date.

On the other hand, if you were to pass the_time something like ‘g:i a’ then it would render a timestamp. In this case, it’s 12-hour time displaying ‘am’ or ‘pm.’

So, using the_date will only result in displaying the date once for the most recent post on a given day and listing the rest of the posts below it, but if you use the_time and pass it parameters used to format the date – namely something like ‘F j, Y’ – then you’ll end up display the date for each post.

Not bad, right?

An easy alternative for unconditionally showing the date on each post.

Share:

Leave a Reply