Increase the WordPress RSS Widget Refresh Rate

While working on the redesign to this blog, I wanted to add the “Interesting Stuff” column you see just to the right. Using the RSS feed widget built into WordPress would be perfect, except for the fact that it only updates ever 12 hours. In today’s Quick Tip, we fix that problem.

The solution is a simple one. Just add this line of code to your theme’s function file:

add_filter( 'wp_feed_cache_transient_lifetime',  create_function('$a', 'return 600;') );

Aha! But What does it all mean? Well let’s take it step by step.

add_filter is a WordPress function call that allows you to ‘hook’ into the WordPress core and execute a function during a certain operation. The two arguments are the hook- that is, when you want to execute a certain bit of code- and the function to execute.

In this case, our hook is wp_feed_cache_transient_lifetime. Simply put, it’s the hook that handles feed refreshes.

Finally, we have create_function('$a', 'return 600;'). This line creates a function on the fly that returns a new refresh time in seconds. I went with every 10 minutes, but use your discretion.

That’s it! Now you have a single line that allows you to control how often your feed widget refreshes.

Leave a comment