Home  »  ArticlesGuidesHow ToProgrammingTechnology   »   How to Stop WordPress From Displaying a Cached RSS Feed

How to Stop WordPress From Displaying a Cached RSS Feed

WordPress can be a powerful tool for publishing all sorts of websites with their own content. One of the strengths of WordPress is that it is able to pull in content from other websites using RSS. This content can then be displayed on your website. The common problem with this feature is that in most cases WordPress will show a cached RSS feed.

Having cached results in your RSS feed may not be ideal especially when the content is being sourced from a site that has fast-updating posts. So this is something the website owner may want to address.

How to Fix Cached RSS Feed

Disable the RSS Feeds Cache Entirely

This can be done by adding action on the wp_feed_options WordPress hook. This modification will disable caching on the RSS feed.

Add the following code to the functions.php file:

function turn_off_feed_caching( $feed ) {
    $feed->enable_cache( false );
}
add_action( 'wp_feed_options', 'turn_off_feed_caching' );

Change the RSS Feed Cache Refresh Cycle

You can use an anonymous function and add a wp_feed_cache_transient_lifetime filter that returns the refresh timer in seconds. This example will refresh after 15 minutes (900 seconds):

add_filter('wp_feed_cache_transient_lifetime', function () {
 return 900;
});

Conclusion

That’s it. The next time you create a new post on your WordPress site the RSS Feed will be cached. For the second example, it will be refreshed after 15 minutes.

Refs:
[ 1 ] – wp_feed_options WordPress Hook
[ 2 ] – wp_feed_cache_transient_lifetime WordPress Hook

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.