How disable feed cache for custom RSS feed in WordPress?

To disable feed cache for a custom RSS feed in WordPress, you can use the wp_feed_cache_transient_lifetime filter hook. This hook allows you to modify the transient lifetime (i.e., the length of time that the feed is cached) for a specific feed.

Here is an example of how you can use this hook to disable feed cache for a custom RSS feed:

function disable_custom_rss_feed_cache( $lifetime ) {
    // Check if this is the custom RSS feed
    if ( is_feed( 'custom_rss_feed' ) ) {
        // Set the transient lifetime to 0 to disable cache
        $lifetime = 0;
    return $lifetime;
add_filter( 'wp_feed_cache_transient_lifetime', 'disable_custom_rss_feed_cache' );

In this example, the is_feed() function is used to check if the current feed is the custom RSS feed, and the $lifetime variable is set to 0 if it is.

Keep in mind that disabling feed cache may affect the performance of your site, as it will need to fetch and process the feed every time it is accessed. You may want to consider using a shorter transient lifetime if you want to cache the feed for a short period of time, or use a different method of caching such as object cache.

Exit mobile version