Meks
Do you know you can try any of our premium WordPress themes for free?Show me the themes
Change WordPress date format to time ago

Change WordPress date format to time ago

59Shares

By default, WordPress offers you a nice solution to change your WordPress date format or time format in general settings of your admin dashboard. However, some people may prefer to have so-called “time ago” format in the similar way to Twitter and Facebook style like posted “10 minutes ago”, “1 hour ago”, “3 hours ago”, etc…

This may be quite useful for websites with lots of content publishing very frequently. But in some cases it is just a matter of your personal taste. In this tutorial, we are going to show you 3 ways of changing WordPress post date to time ago format and use it inside your WordPress themes.

1. Change WordPress date format to time ago using custom template function

In the code snippet below, you will see custom function mks_time_ago() which you can use in any template of your WordPress theme instead of WordPress native function like the_date() and the_time().

Simple as that! We are just using WordPress current_time() and human_time_diff(). Just keep in mind to add this function somewhere in the functions.php file of your theme. Now here is a basic usage example of the function inside of a WordPress theme template file.

2. Using post time and date WordPress filter hooks

This solution is more suitable for those who don’t want to change the theme template files. In the following example we are using a callback function to override built in WordPress get_the_date and get_the_time functions and display time ago format automatically.

That’s it! Just paste this snippet in you theme functions.php file. Also, depending of your theme code and logic, you may only want to use time OR date filters so you can remove unnecessary hooks optionally.

3. Using Meks Time Ago WordPress plugin

For all of you who are not familiar with coding we have created a plugin which will change your post date format to time ago and should work with any theme out of the box. Meks Time Ago WordPress plugin is 100% free and can be downloaded from official WordPress plugin repository.

Once you install and activate the plugin you can go and manage its simple options. The sweetest thing here is the limitation option so you can apply time ago format only for posts which are not older than specific time frame. For example, let’s say that you want to show time ago date format only for posts which are published in the last 5 days while other posts will be displayed in standard date format.

meks_time_ago_options

Live example?

Yes, we are using this “time ago” approach in our several WordPress themes so you can see it live in action on our demo websites for Voice Theme, Throne Theme, and Sidewalk Theme. Feel free to try and let us know what do you think in comments section.

59Shares
Bojan Petrovic

Co-founder and WordPress developer at Meks. He has been involved in the business since 2009. creating themes, plugins and services on top of WordPress, continuously aiming to choose best approaches and work smarter, not harder.

15 comments

Leave a Reply

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

You don't need to have loads of money to get a world-class WordPress website! All our themes are rated with the highest 5-star rating. Have a look and choose the best one for you.
Meks WordPress Themes
Meks