How to Change the WordPress RSS Feed Update Frequency

I recently experienced a problem with the freshness of the RSS Feed on a WordPress site. It wasn’t reflecting the 2 latest posts. I tried searching the web, but my search-fu was weak on this day. Luckily my colleagues in the Seattle WordPress Slack channel were able to help me. My friend Mark came through with the answer.

It’s true what the say about programming — Writing code is easy. Figuring out which lines of code to write is the hard part. The solution the article provided would work. However, the example code could be better. First, I’d rather see a proper function. Doing so gives you more flexibility and clarity. The other way their example code can be improved, is the time of 600 seconds. That’s just ridiculously short. If someone were to blindly copy/paste that code into their production site, that unsuspecting developer might have a whole new problem to deal with regarding performance.

function awnet_update_rss_frequency( $time ){
    // Un-comment the error_log statement to see 
    // the current $time in your debug.log
    // error_log( 'original update (in seconds)=' . $time );
    $time = 4 * HOUR_IN_SECONDS;

    return $time;
}

add_filter( 'wp_feed_cache_transient_lifetime', 'awnet_update_rss_frequency', 20 );

I hope that helps you get your work done a little bit faster.

Sorry, but comments are closed. I hope you enjoyed the article