Last active
November 15, 2017 16:18
-
-
Save dartiss/35b1114cdd222318c1cb8d6c0eb93428 to your computer and use it in GitHub Desktop.
Highlight Old WordPress Posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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">×</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' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.