How to delay posts from appearing in the WordPress RSS feed

Delaying posts from appearing in the WordPress RSS feed saves you in case you publish content accidentally.  Here we show you the methods that can be used to delay posts from appearing in the WordPress RSS Feed.

Why delay posts from appearing in the WordPress RSS Feed?

There might be cases when you have grammar or spelling mistake in the article which you notice only after publishing.. In some cases, the mistakes might go live and get distributed to the RSS feed subscribers. In cases when you have email subscriptions, your subscribers might get the wrong post as well.

So it makes sense to delay the time between your RSS feed and live site. This gives you a time window to check for errors and fix them.

Content scraping websites also use RSS feeds. These sites use RSS feeds to monitor and copy your content as soon as they are live. For a new website with little authority, these content scrapers might copy your content and beat you in the search results.

Delaying an article in the feed allows search engines enough crawling and indexing time before your post appears in the RSS feed.

How to delay posts in WordPress RSS Feed?

Add the below code to a site-specific plugin or your theme’s functions.php file to delay posts in WordPress RSS feed.

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 = '10'; // integer

		// https://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');

The code checks if a WordPress feed has been requested. Then, it will set the current time and the delay time you want between the original date of the post and the current time.

The code also adds a timestamp difference as the WHERE clause to the original query. The original query will now return the posts where the difference of the timestamp is greater than the wait time.

The above-mentioned code uses 10 minutes as the $wait or delay time. You can change the number as needed, but don’t forget to include the time only in minutes.

 

For further questions, or if you need help, please open a support ticket from your HostPapa Dashboard. Click here to learn how to do it.

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache