Show Date on Every Post

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.


Join the conversation! 11 Comments

  1. Well that makes sense now. Thanks Tom. More like this please!

  2. Arrgh … my bad with poor formatting, the HTML ‘code’ tag does not like having PHP tags inside it. Re-replying to (hopefully) make this more clear.


    &lt;?php echo get_the_date( get_option( 'date_format' ) ); ?&gt;

    will also show the date on every post on the same day as well.

    PS: I had to test this as it is what I have been using with my in-progress framework theme.


    &lt;?php the_date( get_option( 'date_format' ) ); ?&gt;

    would be more correct as it echoes the date by default.

    • Your first example is right, but I’m not so sure about your second example (though I did remove the echo statements) – that’s the problem I was trying to outline in the post.

      From the Codex:

      When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date())

      Unless something has changed, using the_date will not display the date for every post. We’d have to use the_time.

  3. Great. Thanks for sharing

  4. I’m searching for wordpress date and time each post and read your post that is nice. Here is also another post which is for show date and time each wordpress post also formatting date and time’s full history.

  5. Hello This is my site i can’t find the location to paste the code to display the post date. As you can see only the latest post display date, plz help me

    • Sorry Afiq, I’m not really into the business of walking through copy and pasting code. If you need some help with this, I’m happy to help you but it falls under consulting.

      If you’re interested, feel free to contact me.

      • Tom. I only want to know which file i should edit.

        • I don’t know because I don’t know the structure of your theme or if any plugins are also hooked into places that would render that information.

          Usually it’s in the index.php template or the single.php template, but there are other places it could be depending on how your developer built the theme.

Leave a Reply