Skip to content

Instantly share code, notes, and snippets.

@dartiss
Last active November 15, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/35b1114cdd222318c1cb8d6c0eb93428 to your computer and use it in GitHub Desktop.
Save dartiss/35b1114cdd222318c1cb8d6c0eb93428 to your computer and use it in GitHub Desktop.
Highlight Old WordPress Posts
<?php
function old_post_message( $content ) {
if ( get_the_time( 'U' ) < strtotime( '1st January 2013' ) ) {
$content = '<div class="alert alert-info alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Due to updates, over time, that have been made to the site and the age of this article, this post may not display correctly. In particular images may be missing or product reviews display incorrectly.</div>' . $content;
}
return $content;
}
add_filter( 'the_content', 'old_post_message' );
?>
@dartiss
Copy link
Author

dartiss commented Nov 15, 2017

There are lots of plugins that will add a message to your posts when they're greater than a specific age (say, 2 years) but that isn't what I wanted - after switching themes and generally rebuilding this site a lot of images were broken, etc. I went through the posts, fixing them, until a specific age - I therefore wanted to highlight any post before a fixed date (i.e. where I'd got to). This, simple piece of code, does this.

Add to your theme's functions.php and, obviously, change the message and date to taste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment