You are here:
  1. Home
  2. Blog
  3. WordPress
  4. 'Old Post' Notice

‘Old Post’ Notice

 |  WordPress

On this blog I have around 10 years of archives. That’s a lot of posts from over the years that may not necessarily reflect the “me” in 2012. I didn’t want people to potentially get the wrong idea about me if they read an old post, but I didn’t want to delete them either: that defeats the point of a blog archive. Solution? Automatically mark old posts with an ‘old post’ warning.

First, to write the warning… this is mine but you would want something that reflects you:

This post is over 6 months old. This means that, despite my best intentions, it may no longer be accurate. Age, motherhood, experience, loss… these things have all changed me from when this blog was started back in the heady (ha) days of my youth.

As much as I would like to go back and edit 10 years of archives to provide an insight into the ‘me’ of now — changed opinions, fresh outlook, updated coding snippets and revised website advice — it would probably take years to do so (by which point I’d have to start again!) This would defeat the point of keeping these archives anyway.

Please take these posts for what they are: a brief look into my past, my history, my journey.

This should be saved in “old-post.php” in your WordPress theme folder.

Next to make the warning appear. I only wanted the warning to appear on individual post pages, so I added this to single.php just above the call to comments_template():

if (strtotime(get_the_time('F j, Y')) < strtotime("-6 months"))

The code takes the date from the current post, converts it to a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC) and then checks it against the converted date from 6 months ago. If the post timestamp is older than 6 months, thus has a lower count in seconds than our "-6 months" date, the old-post.php file which contains our warning is included.

Alternative Method

It's also possible to include your warning without changing the template file single.php. The advantage to this would be if you don't feel comfortable editing PHP or have a premade theme which is overly complex.

Simply add the following to your theme functions.php (making sure it's within a <?php block):

add_filter( 'the_content' , 'old_post_warning' );
function old_post_warning($content) {
	if ( is_single() && strtotime(get_the_time('F j, Y')) < strtotime("-6 months") ) {
		$content.= '<div id="oldpostwarning">';
		$content.= 'your warning here';
		$content.= '</div>';
	return $content;

Your warning will now automatically appear after single posts older than 6 months.

If you want to adjust the time before the old post warning appears, e.g. to have it show on posts older than one year, change "-6 months" to "-1 year" etc.

Like this? Would you rather have this as a plugin that you can easily update via the WordPress Admin panel? Let me know in the comments...

Jem Turner +44(0)7521056376

Comments are closed.

Follow on Instagram