In the WordPress Codex, 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
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(); ?>
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.
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.
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:
index.php template file, wherever you choose to display your copyright statement, add the following:
Copyright © <?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
index.php template files.
<a href="http://example.com/Copyright_Policy/" title="Copyright Policy">Copyright © 200 - <?php the_time('Y') ?></a> <a href="http://example.com/" title="My Blog Example">Fred Smith</a>
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?
- Table Of Date Format Characters On The PHP Website
- Showing Dates Not Just Times in Your Multi-Post Views
- Do You Update Posts or Post Updates?
- Post Meta Data WordPress Plugins
- WordPress Category Feed Links in Your Post Meta Data Section
Site Search Tags: wordpress tips, dates, time, date, wordpress template tags, template tags, date template tags, time template tags, date tags, time tags, post meta data, byline, copyright, wordpress themes, template files
Subscribe Via 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.