Change Refresh Interval of WordPress RSS Widget

How to Change Refresh Interval of WordPress RSS Widget

in RSS Feeds
Google+ LinkedIn

By default, WordPress cache feed or rather the cached feed has a lifetime of 43200 seconds, equivalent to 12 hours. There isn’t an option in WordPress admin panel to purge the cached feed and force WordPress to refresh feed manually. On a specific project you might need WordPress RSS widget to update faster than every 12 hours. For example, if you display stocks price feed on your website then WordPress updating feed every 12 hours is not good because it defeats the whole purpose of displaying stock prices. So in this article I will show you how to change WordPress RSS widget refresh interval. You might also be interested in displaying featured images in RSS feeds and also to change post autosave settings.

Luckily WordPress offers a way to actually reduce or increase the default cache lifetime. We can change refresh interval simply by hooking a function that returns an integer (time in seconds) into the wp_feed_cache_transient_lifetime filter. Following is the code snippet which you can add to your theme’s functions.php file to change default refresh interval of WordPress RSS Widget to 1 hour (3600 seconds) instead of 12 hours.

// change refresh interval of wordpress rss widget
function wcs_rss_widget_refresh_interval( $seconds ) {
    return 3600;
}
add_filter( 'wp_feed_cache_transient_lifetime', 'wcs_rss_widget_refresh_interval' );

The above code snippet will cache the feed for 3600 seconds (1 hour). Setting it 0 actually might disable feed caching.

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *