Delay Your Feed Publishing

Have you ever written a post then hit the publish button only to discover you missed a typo? I've done it a few times even after proofreading my copy. Of course you can always edit the post but the problem is your RSS feed has already been published and sent out. You can't edit that and it will take some time for the caches of the various feed services to clear and reflect your edit. I'll show you how to avoid this problem by adding a simple delay so that your blog does not immediately publish your feed.

In a plain text editor such as Notepad, open your theme's functions.php and add the following ...

//delay feed publishing
function publish_later_on_feed($where) {
global $wpdb;

if ( is_feed() ) {
// timestamp in WP-format
$now = gmdate('Y-m-d H:i:s');

// value for wait; + device
$wait = 'x'; // integer

// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

// add SQL-sytax to default $where
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
}
return $where;
}

add_filter('posts_where', 'publish_later_on_feed');

What we have done is add a filter to the publish_later_on_feed function so that your feed is not published at the same time your post is. You can adjust the time delay to anything you want. Look for the line,

$wait = 'x'; // integer and change x accordingly. For instance, if you wanted a 30 minute delay that line would look like,

$wait = '30'; // integer

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him at WeblogToolsCollection.com where he is a moderator. He also hangs out at the WordPress support forums lending a hand where he can. You can find his political scribblings at RiteTurnOnly.com

Leave a Reply

CommentLuv Enabled