Display a custom message on old posts

Here’s a chunk of code for WordPress that will display a custom message on posts older than a certain date. You might ask, “Why would I need such a thing?” And I’d say you probably don’t but if the post is older than 60 days and not a monthly archive, the person has likely arrived via search engine or permalink.

So, who cares if someone is arriving via search engine? Well, they probably won’t stick around after you’ve given them their tidbit of information. However, you could direct them towards your site’s main page, some other content or even display some AdWords or other advertising (thus avoiding a hit to your loyal readers).

It’s a relatively straight-forward chunk of php code. You’ll probably want to put it in your post template, sandwiched between the function that displays content and the one that displays comments.

<?php 
	$entry_datetime = abs(strtotime($post->post_date)); 
	$time_since = time() - $entry_datetime;   
	$days_since = 60;
	if ($time_since > $days_since * 86400) :
?> 		
 <div class="message-age">
  ## Modify this message
  <p>This entry is more than 60 days old.</p>
 </div>
<?php endif; ?>

This code is GPLd, do whatever you want with it. You could have it display a different message for a post that’s a year old or two years old.

If there’s interest, I can turn this into a simple WordPress plugin but it doesn’t seem overly necessary.