How to change the update time (cache time) of RSS feed block
- Published:
category: WordPress
In WordPress, when receiving and listing RSS feeds of external sites using the “RSS” block of the block editor, it is updated every 12 hours (12 hours are not reacquired). (This is called a feed cache).
This is set as standard as a measure to reduce the processing of the page and the load on the feed source site by receiving the feed and displaying it as a list every time the page with the “RSS” block etc. inserted is displayed. It has been.
However, depending on the site or page, you may want to always receive and display the latest information.
In such a case, you can change the feed cache time arbitrarily by adding the following code to the theme’s functions.php and specifying the time.
7200 in the code means 7200 seconds (120 minutes = 2 hours), so change it to any number according to the purpose.
/********** RSSフィードのキャッシュ時間変更 **********/
/*** rerurnの値を変更することで時間変更可能(秒で指定)***/
function ha_feedcachetime( $seconds ) {
return 7200;
}
add_filter('wp_feed_cache_transient_lifetime','ha_feedcachetime');
$feed = fetch_feed( $feed_url );
remove_filter('wp_feed_cache_transient_lifetime','ha_feedcachetime');
Also, if you want to make it completely on-demand (no cache), just add the following code to functions.php of the same theme.
/***** フィードのキャッシュをオフにする *****/
function ha_turn_off_feed_caching($feed){
$feed-> enable_cache(false);
}
add_action('wp_feed_options','ha_turn_off_feed_caching');
Regardless of which method you use, if you have multiple feed receiving lists on your page, or if you want to view feeds from multiple sites together, the server will be overloaded and your page will slow down. Please check carefully before using.
Reference article (WordPress Codex)
Post Author: Knowledge Base Admin
An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!