Skip navigation

Displaying the Date in Your WordPress Theme

In the , the online manual for WordPress Users, there is an article that will help you set the date and time, so to speak, for your WordPress blog, called Formatting Date and Time, using the PHP codes for the time and date.

Using a combination of WordPress Template Tags and PHP codes for date and time, you can let your readers known when you published your blog post in a variety of ways.

For instance, in the post meta data, you can set the time and time to a format of your choosing, based upon international and cultural time formats, or one of your choosing.

Examples of the various formats for time and dates include:

  • l, F j, Y – Friday, September 24, 2007
  • m/j/y g:i A – 05/12/07 9:35 AM
  • 1, j F Y – Monday, 21 February 2007
  • Y – 2007
  • j F Y – 20 April 2007

You can spread out the date information in your post meta data section in the form of a sentence:

This post was written on the 
<?php the_time('jS'); ?> day in the month
of <?php the_time('F'); ?> in the year of 
<?php the_time('Y'); ?>

Which would result in:

This post was written on the 15th
day in the month of February in the year of 2007

Display the Date the Post was Modified or Updated

As of WordPress version 2.1, you can now showcase the date your blog post was modified, not just published. The the_modified_date template tag displays the date the post was last modified, and the_modified_time() displays the last modified time. These work only when used within the WordPress Loop, the code that generates the post content information.

Published <?php the_date('F j, Y'); ?>
Modified <?php the_modified_date(); ?>

Displays:

Published August 1, 2004
Modified April 23, 2007

This is helpful for articles which require updates, or for helping update your readers so they know when the blog post was last updated.

The article on the WordPress Codex, Designing the WordPress Post Meta Data Section, covers a lot of ways to use dates and times in that section.

You can find more variations on using the date and time in the the_date and the_time() WordPress Template Tags, but let’s take this a little further.

Adding the Date and Time To Your Byline

The date and/or time can be incorporated into the byline under the post title, in the post meta data section, or elsewhere in your blog.

For example, your byline can read:

By <?php the_author(); ?> on <?php the_date('F j, Y'); ?>

Would display the author’s name as set in the Administration Panels under Profile with the date:

By Fred Smith on August 31, 2007

Let’s look at another practical use for your WordPress Blog: on your copyright statement.

Copyright Date

While most copyright statements don’t need the date, in some countries, the date should be included in the copyright statement. Many bloggers manually code this date in their copyright statement, but what happens next year? Why not use the PHP date commands to recreate a constantly updating year on the copyright statement?

Using the PHP date commands, you could set your copyright statement to automatically update every January, when the current year changes:

In your footer.php, single.php, or index.php template file, wherever you choose to display your copyright statement, add the following:

Copyright &copy; <?php the_time('Y') ?> <?php bloginfo('name'); ?>

This will display:

Copyright © 2007 Lorelle on WordPress

However, this method will only show the copyright as the current year, not the original year of publishing, which is the preferred method. Let’s change this so it includes a static “first” year and showcase your name instead of the blog’s title. I recommend you include links around the copyright to your copyright policy, and around your name to your blog, to help you track any incoming links from those who may be violating your copyright. This works best when used in the post content area on the single.php or index.php template files.

<a href="http://example.com/Copyright_Policy/" title="Copyright Policy">Copyright 
&copy; 200 - <?php the_time('Y') ?></a> 
<a href="http://example.com/" title="My Blog Example">Fred Smith</a>

Results in:

Copyright © 2000 – 2007 Fred Smith

Have you come up with some other tips and tricks for using the PHP date and time codes within your WordPress blogs?

Related Articles

Member of the 9Rules Blogging Network


Site Search Tags: , , , , , , , , , , , , , ,
Feed on Lorelle on WordPress Subscribe Feedburner iconVia Feedburner Subscribe by Email

Copyright Lorelle VanFossen, member of the 9Rules Network, and author of Blogging Tips, What Bloggers Won't Tell You About Blogging.

40 Comments

  1. Posted September 3, 2007 at 6:47 pm | Permalink

    Lorelle,

    Great post!!!

    Is there a easy way to only display the last modified date if it applies?

    I would like to have nothing there unless the post has ever been modified.

  2. Posted September 3, 2007 at 7:34 pm | Permalink

    There may be an easier way to do this, but I would match the original date against the modified date and if they were different, post the modified date. I tested this out on my blog, so it should work for you!

    Modified: < ?php $origdate = get_the_time();
    $moddate = get_the_modified_time();
    if ($origdate != $moddate){ the_modified_date();} ?>

    If the above code doesn’t display, I also reposted it here

  3. Posted September 3, 2007 at 8:38 pm | Permalink

    The link above goes to a 404 Page Not Found, Jenn. And it looks like you need a few lessons on Writing and Publishing Code in Your WordPress Blog Posts, which applies to comments, too. 😀

    Turn those < into &lt; for a start.

    Thanks for the try. You are saving me from looking this up.

  4. Posted September 3, 2007 at 10:09 pm | Permalink

    aaahhhhh great informative post, thanks 🙂
    Bookmarked and will use for future reference

  5. Posted September 3, 2007 at 10:13 pm | Permalink

    Ahh alas. My braindead self managed to move the page for organizational purposes after I posted the link! Sorry about that! The code lives here now if you’re still looking, Kyle!

    Now off to brush up on “Writing and Publishing Code in your WordPress Blog Posts”. Thanks Lorelle! Glad you’re back to posting!

  6. Posted September 4, 2007 at 7:41 am | Permalink

    I cleaned it up for posting and added it to your comment above, Jenn. Thanks so much. I use a WordPress Plugin to do this on my main blog, which doesn’t work in the latest version of WordPress, so I’m going to try this. THANK YOU!

  7. Posted September 4, 2007 at 9:59 am | Permalink

    Any way to abbreviate the month? It won’t fit in my little date box…

  8. Posted September 4, 2007 at 10:04 am | Permalink

    Found my own answer:

    http://us2.php.net/date

  9. Posted October 1, 2007 at 12:00 am | Permalink

    In what files does this need to be placed?
    Published
    Modified
    Thanks.
    June

    • Posted October 5, 2007 at 12:32 pm | Permalink

      @June: You can put these codes anywhere you need them as stated in the article. They can go in the footer template file of your Theme for copyright dates, or in the single.php for the byline, and many other places.

  10. Posted February 27, 2008 at 12:28 am | Permalink

    This is great. I have no experience in coding. And I was getting used to the theme I had chosen (which is a modified version of the NT-greeny theme). But this theme has no option for displaying the dates.
    This had been bothering me for a while. I read through other tutorials for this, but for a novice like me, it was difficult to follow through…

    But this post was great!! I was able to implement the date. AND it also showed links and sections for more experienced coders.

    I am having some layout issues, which I should get sorted somehow. I don’t know what I messed up, but it isn’t too serious. In any case, the date finally displays. Hurrah!
    🙂

  11. Posted February 27, 2008 at 9:11 am | Permalink

    @ Hammy:

    Designing a web page is like playing with dominoes. For every small change, there is an equal, and usually opposite and unwanted change. 😀

  12. Victor Munoz
    Posted February 29, 2008 at 4:48 pm | Permalink

    Lorelle,

    Thanks for the post, but I am not sure the following is correct, you write:

    “Why not use the PHP date commands to recreate a constantly updating year on the copyright statement?

    Using the PHP date commands, you can set your copyright statement to automatically update every January, when the current year changes:”

    And you suggest this code:

    “Copyright © … ”

    When I tried that I kept getting the post year, not the current year, which is what I wanted for the copyright statement. To always get the current year, this works:

    Copyright ©

  13. Victor Munoz
    Posted February 29, 2008 at 5:00 pm | Permalink

    Ok, one more time:

    Copyright © php echo date(‘Y’);

    as opposed to:

    Copyright © php the_time(‘Y’);

    (I’m leaving off the php start and end markers so the important part displays.)

  14. Posted February 29, 2008 at 5:41 pm | Permalink

    There are WordPress Template tags for handling the date, and PHP commands. That’s the difference. Yes, one creates a static date, but the one at the end of my article dealing with copyright changes with the actual year, not a fixed date, which is the intention of that usage. Does that answer your question?

    To write code in blog posts and comments, see Writing and Publishing Code in Your WordPress Blog Posts.

  15. Posted July 6, 2008 at 9:04 am | Permalink

    Would it be possible to show date and time in another language? I have an Italian blog, and date and time show up in English.
    thank you.

  16. Posted July 6, 2008 at 6:35 pm | Permalink

    @ francesco:

    If your WordPress Theme has been set up for localization, check out WordPress in Your Language in the WordPress Codex for information on how to do this, and support, in your language.

  17. Posted August 6, 2008 at 2:23 pm | Permalink

    Hi all!

    I just discovered that even though my date settings seems to be right, the leading zero is missing when the date is 1 to 9. Not sure where and how to add it. Date format for Sweden is

    2008-07-07 (july 7, 2008) or 2008-11-21 (November 11, 2008).

    Where should I add that missing zero, so it only shows when the day or month is between 1 and 9?

  18. Posted August 6, 2008 at 3:10 pm | Permalink

    @ Niklas Wikman:

    I’m not sure I understand your issue as it looks right to me. If you are looking for July 07, 2008, that’s not a traditional date format. That will have to be manually changed. See Formatting Date and Time. I also do not understand where you are finding this date, within the Administration Panels, in the post meta data section of your blog post, or what, but I’m sure you have reported it in the WordPress Support Forum and the WordPress Bug Report so people can investigate this further.

  19. Posted October 27, 2008 at 6:35 am | Permalink

    Hi Lorelle,

    You’ve got a great blog that you keep getting people like me to come to your blog again and again and again. I wonder how you do this very well indeed?

    I have a small issue here.

    On my blog, I have my posting feature enable for my articles page and the front page is a static page.

    The point is the date, posted by Author and comments link is not showing even though I have enabled the comments, ping and the date is already configured in my wp-admin.

    I also a MCEcomments plugin which is activated as well. Hope it works as well so as to enable visitors to write comments using the comment editor.

    Please help me with this issue.

    Thanks.

    Regards,
    Ron S

  20. Posted October 27, 2008 at 10:24 am | Permalink

    @ Ron S:

    Your best help in issues like this come from the WordPress Support Forum, especially since, like right now, I’m traveling a lot and not able to respond to specific inquiries. The issue could be that since you have done some major customization on the front page, you removed the date, author and comments link from the WordPress Theme template file. Without digging into the Theme, I would have to assume that the issue involves the template files.

    I see also that you have a TON of Javascript in the header which creates and controls content as well as design and features. There is a lot of stuff going on with your page, much of it which should be cleaned up and possibly causing conflicts, so this will take more than a 30 second free glance to figure out.

    Sorry I can’t get more specific right now. Good luck with it and let me know what you find out.

  21. Richard
    Posted January 24, 2009 at 11:54 am | Permalink

    it is very good and wonderful

  22. Priyan
    Posted March 16, 2009 at 11:31 am | Permalink

    Is it possible to display the short name of the months like ‘Feb’ instead of ‘February’ with the the_time tag ??

  23. Mano
    Posted May 21, 2009 at 9:10 pm | Permalink

    How to add the date and time on each page of the website and where to put the code as me very new to wp and php environment.. Shld i put in header file or where please advice !!!!!

  24. Posted December 5, 2009 at 2:21 am | Permalink

    Thanks .. I was looking for this hint along time ago

  25. Posted January 16, 2011 at 7:50 am | Permalink

    Thank you, was having great difficulty getting the dates to display on articles so very much appreciated, now I’ll I need to work out is how to get the font to fit in with the rest of the theme.

  26. Posted December 31, 2011 at 2:55 am | Permalink

    Lorelle,

    As someone mentioned above (perhaps they didn’t make themselves all that clear), you’ve made a mistake under the copyright/footer code suggestion.

    <?php the_time('Y') would ouput the year of post/page currently being viewed, which is obviously not at all what you want. Instead you should use the date() function, like so: <?php date('Y')

    • Posted January 1, 2012 at 11:49 pm | Permalink

      I’ll double check but the_time() is a WordPress template tag not a PHP reference. The article is discussing the use of that tag. In the examples, especially under copyright, I want the current year the page is being viewed. This information is generated in areas within the WordPress Loop. Outside of the Loop, the PHP date could easily be used. Either one will work.

    • Posted January 1, 2012 at 11:53 pm | Permalink

      Yes, I am well aware of what the_time() is… As described in that function’s codex page, which you linked to, it “Displays the time of the current post.”

      When you are putting the Copyright of your site in the footer, you want the current year, not the year that the post was written in, you said it yourself “I want the current year the page is being viewed.” and thus the_time() will not give you the information you want, as I said, date(‘Y’) is how you’d get the current year.

  27. Posted January 2, 2012 at 7:36 am | Permalink

    Remember that with copyright, older is better. Specifying a range like your 2nd copyright example is better than just keeping the current year.

    Copyright date is when you established the copyright, and constantly upgrading it defeats the purpose.

    • Posted January 2, 2012 at 12:35 pm | Permalink

      @Bill: Absolutely, which is why I added the second instructions, but you are also right, as is Joachim, that it isn’t clear. I’ve edited it to make it more specific. Thanks for nagging me to update this article after so many years.

  28. ProfesorYeow
    Posted November 12, 2012 at 5:53 am | Permalink

    I have a problem. When I use in the header () don’t work… anyone know how to solve or only work in the loop? Thanks

    • Posted November 14, 2012 at 5:40 pm | Permalink

      You are going to have to be more specific in your request for help. Try the WordPress Codex articles on the WordPress Loop.

  29. Steve Moss
    Posted January 23, 2015 at 6:21 am | Permalink

    Thanks for the article;) I had to use
    IN THE SAMPLE:

    <a href="http://example.com/Copyright_Policy/" title="Copyright Policy" rel="nofollow">Copyright
    © 200 - </a>
    <a href="http://example.com/" title="My Blog Example" rel="nofollow">Fred Smith</a>

    For some reason the date came out to be 2010 instead of 2015 with the statement.

    • Posted January 23, 2015 at 4:35 pm | Permalink

      Since the code didn’t publish in the comments, I don’t know what you did, but check the date of your site in Settings > General.

  30. Darker John
    Posted February 11, 2015 at 8:51 pm | Permalink

    Dear Lorelle,

    Thank you very much for your kind advice. Please kindly guide me to show date and time in header of my blog.

    Best Regards,

    Darker John

    • Posted February 12, 2015 at 2:29 am | Permalink

      You will need to contact the Theme author or WordPress.com or WordPress.org Support Forums for help with your specific Theme. If you are on WordPress.com, the answer is no, you cannot add the date and time to the header of your site. Thanks.

  31. Posted July 9, 2015 at 11:45 pm | Permalink

    I have been searching on the web higher than three time of
    late, but I in no way discovered any sort of intriguing
    article similar to yours. It is fairly well worth enough personally.


8 Trackbacks/Pingbacks

  1. […] Cómo visualizar la fecha en un theme de WP […]

  2. […] posts about Displaying the Date in Your WordPress Theme. A useful post about different styles of showing the date, using it for copyright date and in the […]

  3. […] Displaying the Date in Your WordPress Theme: The time and date plays an important role in your WordPress Theme. In the byline or post meta section, it tells readers when the post was published. It can also be used elsewhere to provide chronological or date information about your blog and blog post with these tips. […]

  4. […] Lorelle put the_time(); too, so I guess I might as well leave it like that. Tagged with: 2008 • […]

  5. […] How many of you still update your themes footer every year to change the copyright date? Thanks to a small snippet of code, you can add this to your footer.php file which will negate the need to manually change the copyright information every year. The code snippet is php the_time(‘Y’) An excellent primer for how to use this snippet within the footer.php file is explained via Lorelle VanFossen. […]

  6. […] Displaying the Date in Your WordPress Theme: The time and date plays an important role in your WordPress Theme. In the byline or post meta section, it tells readers when the post was published. It can also be used elsewhere to provide chronological or date information about your blog and blog post with these tips. […]

  7. […] Displaying the Date in Your WordPress Theme: The time and date plays an important role in your WordPress Theme. In the byline or post meta section, it tells readers when the post was published. It can also be used elsewhere to provide chronological or date information about your blog and blog post with these tips. […]

  8. […] Displaying the Date in Your WordPress Theme […]

Post a Comment to Lorelle VanFossen

Required fields are marked *
*
*