You’re right. The code you had didn’t use any logic to determine whether to add the CSS class or not. Try this:
function skips_add_update_status($classes) {
//Instantiates the different date objects
$created = new DateTime( get_the_date('Y-m-d g:i:s') );
$updated = new DateTime( get_the_modified_date('Y-m-d g:i:s') );
$current = new DateTime( date('Y-m-d g:i:s') );
//Creates the date_diff objects from dates
$created_to_updated = date_diff($created , $updated);
$updated_to_today = date_diff($updated, $current);
//Checks if the post has been updated since its creation
$has_been_updated = ( $created_to_updated -> s > 0 || $created_to_updated -> i > 0 ) ? true : false;
//Checks if the last update is less than n days old. (replace n by your own value)
$has_recent_update = ( $has_been_updated && $updated_to_today -> days < 14 ) ? true : false;
// check whether $has_recent_update is true
if( $has_recent_update ) {
//add update class
$classes[] = 'update';
}
return $classes;
}
add_filter('post_class' , 'skips_add_update_status');
I removed the check for whether it’s ever been updated as you didn’t seem to be using that.
To build on that, I’d argue that noting a recent post is more presentational than content. Therefore, you could do the whole thing with CSS. Using some made up classes because I don’t know what your HTML looks like, it might be like this:
.update .post-title:before {
content: "[Updated!]";
}
Depending on your styling requirements, you might want something a little more fancy:
.update .post-title:before {
content: "[Updated!]";
display: inline-block;
padding: 2px;
background-color: red;
color: white;
}