TJ Kelly

WordPress Post Date Not Showing

And if you’re like me, and you don’t publish posts that frequently, you may never know that publishing two posts on the same day can cause a problem for WordPress’ the_date() function.

Welp, guess what.

[blog_stripe]

Getting around the_date() problem

It’s a pretty easy fix. If you notice your WordPress post date not showing up on an archive page, you just have to pick another function. WP offers two suitable replacement options:

  1. the_time()
  2. get_the_date()

Since WordPress 3.0 was released, these are the two functions you can choose from. Both require a date-specific format string to get the right effect. Since you can set the date for a post/page in the admin interface, WP recommends combining the_time() with get_option() and using this quick line of PHP to print your post dates:

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

[/blog_stripe]

Why doesn’t the_date() work?

Here’s what WordPress has to say in their 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()).

They don’t offer any further explanation than that. It’s not for us to wonder why, is it, oh great Automattic? Whatever, I’m not a WordPress core developer so I won’t judge. But whatever the case, all that means is that you have to play it safe and avoid using the_date() in your archives.

[blog_stripe]

Any other annoying WordPress gripes today?

No, not today. Stay tuned, it won’t be long until the next one comes along. The good news is that they’re almost always easy to work around and the WordPress developer community is strong and growing, always helping other WP devs improve their sites.

[/blog_stripe]

2 thoughts on “WordPress Post Date Not Showing

Leave a Reply

Your email address will not be published. Required fields are marked *