X

How to Notify Readers of Old Posts in WordPress

Snippets by IsItWP

Are you looking for a way to display a message to your users to notify them when a post over an year old? While there’s probably a plugin for this, we have created a quick code snippet that you can use to notify readers of old posts in WordPress.

Instructions:

All you have to do is add this code to your theme’s single.php file.

<?php
$time_defined_as_old = 60*60*24*365; // A Year
if((date('U')-get_the_time('U')) > $time_defined_as_old) {
  echo '<div class="notice"><strong>Notice</strong><br />This article is published more than one year ago. Information in this article might be irrelevant with current situation</div>';
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 43 photography themes for WordPress and how to create a contact form in WordPress.

Comments  Leave a Reply

  1. Is there a way to have it notify in admin instead of live if a post has reached a certain age?

    1. How are you thinking to display this? like something within the posts columns.

      1. Exactly, just an indicator next to the post that it hasn’t been updated in X number of months,days. 

        Also, it may be beneficial to have items in “Right Now” on the dashboard. older than 6 months, 1 year, etc.

        1. Hi Zach I think you would need to have something on the dashboard, if the site was like wpsnipp.com I have over 460 posts as a result I would never see the icon unless I viewed very old posts. Ill look into the idea see if I can’t post a new snippet, great idea though.

        2. The exact same thing would occur with us as well. That’s why I was saying adding it to “right now” might work. 

  2. Tweets that mention Wordpress Notify readers of old posts – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com February 16, 2011 at 3:45 pm

    […] This post was mentioned on Twitter by HTMLfrp, WPSNIPP. WPSNIPP said: #wordpress Notify readers of old posts http://bit.ly/g5vVcB #blog please RT 🙂 […]

  3. WordPress Notify readers of old posts – wpsnipp.com WordPress code snippets for your blog…

    Adding this to your wordpress theme will display a message to your visitors to notify them when a post is over a year old….

Add a Comment Cancel reply

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!