Dukeo » WordPress » Delay RSS Feed: How To do This with WordPress

Delay RSS Feed: How To do This with WordPress

Steven 2 responses WordPress

So many times, I have published a post to only realize just after a few seconds that I forgot to correct some errors in it. Of course you can always edit the post to correct the error but the problem is that your post has already been published in your RSS feed.

The best way to avoid this problem is to create a delay between the publication of the post on your WordPress blog and its availability in your RSS feed.

You just need to edit the file functions.php located in your theme folder, and paste the following code:

<?php
function publish_later_on_feed($where) {
  global $wpdb;

  if (is_feed()) {
    $now = gmdate('Y-m-d H:i:s');
    $wait = '5';
    $device = 'MINUTE';
    $where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
  }
  return $where;
}

add_filter('posts_where', 'publish_later_on_feed');
?>

This snippet of code will create a delay of 5 minutes between your post going live on your blog and being published in your RSS feed. If you are not satisfied with a 5 minutes delay, you can change it by editing the $wait variable on line 6. (Keep in mind that the delay MUST always be an integer).

If you enjoyed this article,
Get email updates

Join for Free »

2 Comments

  1. Earl Grey

    Nice one.
    I will implement that and thanks for that tip.

  2. Nizam

    This is really useful. Thanks Steven for this code :)