This WordPress Tutorial will teach you how how to display the WordPress post date as Time Ago eg, “posted 6 Days ago” in place of the more traditional WordPress post date format of 1st May 2012 for example. You will be required to edit some of your WordPress themes template files to achieve this change on an existing theme. As always we also recommend that you use a code focused text editor when editing any template files.
Firstly you will want to find the instances of the post date function within your existing themes template files, the function you are looking for will be similar to the example below. Your exact date function may also have letters contained in the code snippet, this is normal and is the snippet you are looking for.
Basic Files To Check
- index.php
- single.php
- tag.php
- category.php
- *-loop.php.php
<?php the_date(); ?>
To display your date function as time ago replace all of your original date function snippets contained within your theme template files with the code below.
<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>
Any questions or improvements on this technique as always please leave a comment.
Leave a Reply
You must be logged in to post a comment.