X

How to Delay RSS feed in WordPress

Snippets by IsItWP

Are you looking for a way to easily delay your posts to RSS feed? Delaying can help in fixing the mistakes before your posts appear on the feed. While there’s probably a plugin for this, we have created a quick code snippet that you can use to delay RSS feed in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function publish_later_on_feed($where) {
	global $wpdb;

	if ( is_feed() ) {
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '5'; // integer
		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
		$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}

add_filter('posts_where', 'publish_later_on_feed');

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 15 best content marketing tools and how to create a custom user registration form in WordPress.

Comments   Leave a Reply

  1. Can I use this to delay the posting of the topic feed from bbpress?
    Thanks!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!