PressTigers

Converting WordPress Posts Timestamp to ‘Time Ago’ Format

WordPress by default provides a way to change your WordPress date format or time format. You can change it from the general settings of your WordPress Dashboard.

Sometimes, you may require “time agoformat on your website, same as followed by Twitter and Facebook. WordPress provides certain functions i.e. the_date() and the_time() which are used to display or return date or time on the posts/pages in the following sample formats:

  • “1 Hour Ago”
  • “2 Hours Ago”
  • “1 Day Ago”
  • “2 Days Ago”
  • “1 Week Ago”
  • “2 Weeks Ago”
  • “1 Month Ago”
  • “2 Months Ago” and so forth

To achieve this functionality, use the following code within the loop or in any template of your WordPress theme:

Simply remember to include this code somewhere in the functions.php file of your Theme.

User Comments

Leave a Reply

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

    Get in Touch