What is the WordPress default feed cache recreation time? How to change it?

When WordPress reads a remote feed with fetch_feed() (for example in the dashboard news widget), it saves the result in a transient so it does not ask the other site every time. The default cache time is 12 hours, which is 43200 seconds.

Change it with the wp_feed_cache_transient_lifetime filter. The filter gets the time in seconds, and the feed URL:

$default = apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, 'https://example.com/feed/' );
echo "Default: $default seconds\n";

add_filter( 'wp_feed_cache_transient_lifetime', function ( $seconds, $url ) {
	return 30 * MINUTE_IN_SECONDS;   // cache for 30 minutes
}, 10, 2 );

$new = apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, 'https://example.com/feed/' );
echo "After the filter: $new seconds";
Output

Default: 43200 seconds
After the filter: 1800 seconds

A shorter time shows new feed items faster, but uses more requests to the remote server. This is not the same as the feed of your own site, which is made fresh on every request.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the WordPress default feed cache recreation time? How to change it?
How to increase maximum execution time in PHP and WordPress?
What are transients in WordPress?
What is WP-Cron in WordPress? How is it different from a real cron job?
How to speed up a WordPress site?