Displaying WordPress Post Time Like Twitter – Many people use well-known social media such as Facebook and Twitter, and in both of these social media after we update comments or make tweets, times will appear such as: 1 hour ago or 1 day ago. If you prefer to show the time on your WordPress blog in a more user-friendly way like on those social media, there is a WordPress function called “Human Time Diff“Which you can use.
By default WordPress displays time in the usual way, namely Day, Month and Year as shown above which I circled in red, but if you use Human Time Diff it will appear as “3 Days ago“Or”2 hours ago” etc. the same style of date used on Twitter and Facebook, with which people have become accustomed to seeing it.
If you want to display this for posts, regardless of the date that will be displayed in your theme, then in this tutorial article I will show you how to display the time of WordPress posts like twitter and facebook which is more interesting than in general in WordPress.
To do that you only need to replace the time code with this code:
<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>
Apart from posting, you can also replace it to display the time in the comments, with this code:
<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>
Here are the results after you change the code time in the WordPress theme you are using with the Humman Time Diff code. Look at the picture I circled in red.
Please try to apply the code above to change your WordPress time to be more attractive like on social media, you find and change the code in your WordPress theme, usually the WordPress theme code is like . but each theme has a different code in displaying the time, you practice offline first to be more flexible in applying it. And the code that you want to replace is usually in index.php, single.php, archive.php or anywhere that shows the time. just learn or if you want to ask please leave a comment in the comments column below.
Hopefully the above article helps you change the time, like on Twitter or Facebook. 🙂