If post hasn’t been modified recently in WordPress

Today an issue came up where a reader of one of a site I manage was referring to content that was out of date. Normally that’s not a problem but in this case it is a timely pandemic documentation page where the content is very likely to be out of date within a couple months if its not routinely updated.

To solve this challenge I decided to write a small function that will check the last modified date of a post and place an alert below the title and above the content. That notice would read…

This page has not been updated in 60 days. The information below may be outdated.

Which is a casual way of alerting the reader that if this information is timely perhaps check elsewhere on the site for a newer post. Likewise, if that person is looking for an older post they can safely disregard the notice. posting a discrete notice can come in handy depending on the context that brought a reader to the post.

Functions.php

<?php
// If post is older than 60 days return true
function jd_is_old_post($days = 60 ) {
	$days = (int) $days;
	$offset = $days*60*60*24;
	if ( get_post_modified_time() < date('U') - $offset )
		return true;
	
	return false;
}
?>

Place within the WordPress Loop

<?php
// If post is older than 60 days display this notice
if ( jd_is_old_post() ) {
	echo '<div class="old-post-notice">';
        echo '<p><strong>This page has not been updated in 60 days. The information below may be outdated.</p></strong>';
    echo '</div>';
} 
?>

WordPress Performance Audit

I’m on vacation this week!

So naturally I decided to start a WordPress performance audit of my personal websites to purge any under-performing plugins as well as evaluate my Child Theme for improvements.

I audit plugins no less than every six months. If a plugin hasn’t been updated in that time I’ll consider removing it from my website.

Plugins

I removed AMP for WordPress and Redis Object Cache.

AMP for WordPress is great if you want that Google love but its overkill for my personal blog. Ironically it hinders site performance a bit so removing it made sense. With AMP removed Redis Object Cache became unnecessary so that was removed as well. I’ll likely need to cleanup some database tables as a result and WPOptomize is perfect for removing old cruft so I’ll do that next.

Plugins That Remained

Progressive Web Apps for WordPress which I recently started using earned a top spot on my site. Not only does it easily set up progressive web app support, it seems to provide a performance boost as well.

Lazy Loader provides lazy loading until WordPress 4.5 is released and becomes a core feature.

The IndieWeb Suite

IndieWeb, Semantic-Linkbacks, Webmention, and Micropub are enhancing my site as a social media hub.

  • IndieWeb – integrates this site with Twitter
  • Semantic-Linkbacks – provides additional commenting features
  • Webmention – Allows users to provide a link to their website as a comment.
  • Mircopub – uses IndieAuth to for third party integration for apps like Quill

Security

I use Wordfence’s two factor security login app to provide an additional layer of protection. Understandably, the full version as it doesn’t play nicely with Micropub as it allows third party access.

Child Theme

I added OpenGraph support so Featured Images show up on social media posts to my blog. Jetpack had provided that previously but I decided to remove it as I wasn’t making full use of all its features.

Chromium website audit
Pretty snappy results

Because PWA caches the browser with service workers a website becomes available offline. Reloading a webpage can result in a page refresh of less than 200ms because its stored locally on your device. Not quite as quick as Gatsby JS or Hugo…But pretty close.