WordPress Minor Edits Hack

Update: This is now available as a plugin – see here.

One of the more irritating aspects of WordPress, at least from a feed subscriber’s perspective, is that minor edits cause the last-updated date to change. The knock-on effect is that the post will find its way back to the top of an atom feed causing readers to see it again. Not the desired effect if you are, for example, correcting an insignificant typo, updating a moved link or adding a category, and even worse if you were to reorganise categories and thus blitz your poor readers with a whole batch of old posts all at once.

In the brief time I’ve looked at this, I haven’t managed a plugin-only solution, but what follows is a fairly simple hack to allow you to specify that a particular edit is minor, and thus get WordPress to leave the last-updated date alone.

Based on an unadulterated WordPress 2.6, you can do the following. In wp-admin/edit-form-advanced.php, insert these two lines:

<input id="minor_edit_checkbox" name="minor_edit" type="checkbox" value="minor_edit" />;
<?php _e('Minor edit') ?><br/>

AFTER this one:

<p class="submit">

Then, in wp-includes/post.php, change this:

if ( $update || '0000-00-00 00:00:00' == $post_date ) {
	$post_modified     = current_time( 'mysql' );
	$post_modified_gmt = current_time( 'mysql', 1 );
} else {

TO this:

if ( $update || '0000-00-00 00:00:00' == $post_date ) {
	if(true!=$minor_edit) {
		$post_modified     = current_time( 'mysql' );
		$post_modified_gmt = current_time( 'mysql', 1 );
	}
} else {

Now when you edit a post, you should see a new checkbox as shown in the picture above. Everything will behave as normal if you leave it alone, but if you check it before clicking the Save button, the last-updated date will not change and the post will remain where it was in the Atom feed.

It shouldn’t need saying, but I’ll say it – follow these instructions at your own risk!

As for a plugin, the first change could easily be accomodated by inserting a hook into the main codebase at the relevant point. How to deal with the second is not so obvious. For reference, Ticket #5196 and Idea #272.