Post is older than

Adding this first block of code to your functions.php will allow you to check the age of a post to see if it is older than a set number of days. Great if you want to display some some information related to the post after set number of days or even stop displaying the post altogether.

   function is_old_post($days = 5) {
       $days = (int) $days;
       $offset = $days*60*60*24;
       if ( get_post_time() < date('U') - $offset )
            return true; 
       return false;
    if ( is_old_post(10) ) {
      // do something if the post is old
      } else {
      // do something if the post is not old

Comments  Leave a Reply

  1. Awesome, thanks! What would be the best way to translate this function
    into hours instead of days? I tried simply removing the *24 from the equation, but this did not provide accurate results.

  2. thanks, using this on my site.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!