Solution to WordPress Not Showing Date for Posts in the Same Day

Solution to WordPress Not Showing Date for Posts in the Same Day

July 2, 2020

You’re making a neat custom WordPress theme but you’ve noticed that the date for your blog posts aren’t displaying if they were published on the same day.

Actually, only one post displays the published date while the rest that were published on the same day are a no-show.

I ran into this issue while I was learning how to build custom WordPress themes from this tutorial:

Not throwing any disses at followandrew (the instructor in the video). I really enjoyed his tutorial and learned so much!

I just suspect he was quickly prototyping this theme as he was recording and perhaps forgot to consider this small detail.

In his tutorial, he uses the WordPress function the_date() to display the post’s publish date: 

<?php the_date(); ?>

Unfortunately, the result is that only one date will be displayed per day, per post—even if there are multiple posts within the same day.

Only one date listing will show per day worth of posts shown in the loop, even if the function is called several times for each post.

WordPress Code Reference for the_date

The Solution

Instead of using the_date function, use the get_the_date() function like so:

<?php echo get_the_date(); ?>

This will always return a date, regardless of if there were multiple posts within the same day or only a single post in a day.

Unlike the_date() this function will always return the date.

WordPress Code Reference for get_the_date

This should fix the problem and have your dates proudly displaying in no time 🤓

For more information on the get_the_date() function, such as parameter options or date formatting, see the WordPress code reference for this function: https://developer.wordpress.org/reference/functions/get_the_date/

More on the echo keyword used in the php function: https://www.php.net/manual/en/function.echo.php

More on the_date() WordPress function: https://developer.wordpress.org/reference/functions/the_date/