Hello @reachingout,
Please use the following PHP code – paste in a text editor, and save as a PHP file, for example “hummingbird-cache-inclusions.php“:
<?php
/**
* Plugin Name: [Hummingbird Pro] Page cache only on specific URLs
* Description: Reverses the behavior of the "Exclusions" field, allowing caching only on specific URLs
* Author: Anderson Salas @ WPMUDEV
* Task: SLS-5039
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
add_action( 'plugins_loaded', function() {
if ( ! defined( 'WPHB_VERSION' ) ) {
return; // Hummingbird is not installed/enabled.
}
if ( ! function_exists( 'wpmudev_hb_should_cache_url' ) ) {
function wpmudev_hb_should_cache_url( $uri ) {
global $wphb_cache_config;
if ( null === $wphb_cache_config || empty( $wphb_cache_config->exclude_url ) ) {
return false;
}
$exclude_urls = $wphb_cache_config->exclude_url;
$uri_pattern = array_filter( $exclude_urls ); // Remove empty values.
if ( empty( $uri_pattern ) ) {
return false;
}
$uri_pattern = implode( '|', $exclude_urls );
$invert = false !== strpos( $uri_pattern, '!' );
$extra_pattern = null;
if ( $invert ) {
$uri_pattern = str_ireplace( '!', '', $uri_pattern );
// We still need to exclude some URLs (wp-login.php, xmlrpc.php, etc.)
$extra_pattern = 'wp-.*\.php|index\.php|xmlrpc\.php|sitemap[^\/.]*\.xml';
}
if ( preg_match( "/$uri_pattern/i", $uri ) ) {
if ( null !== $extra_pattern && preg_match( "/$extra_pattern/i", $uri ) ) {
return false;
}
return true;
}
// Now do the same, but test the URI as part of the full URL.
$http_host = isset( $_SERVER['HTTP_HOST'] ) ? htmlentities( stripslashes( $_SERVER['HTTP_HOST'] ) ) : '';
$http_port = isset( $_SERVER['SERVER_PORT'] ) && 443 === (int) $_SERVER['SERVER_PORT'] ? 'https://' : 'https://';
if ( preg_match( "/$uri_pattern/i", $http_port . $http_host . $uri ) ) {
if ( null !== $extra_pattern && preg_match( "/$extra_pattern/i", $http_port . $http_host . $uri ) ) {
return false;
}
return true;
}
return false;
}
}
add_filter( 'wphb_should_cache_request_pre', function( $cache ) {
if ( is_admin() || wp_doing_ajax() || wp_doing_cron() || ! is_bool( $cache )) {
return $cache;
}
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? stripslashes( $_SERVER['REQUEST_URI'] ) : '';
if ( ! wpmudev_hb_should_cache_url( $request_uri ) ) {
$cache = false;
}
return $cache;
});
}, 10 );
Upload it to /wp-content/mu-plugins/ directory on the server, so that it runs as a must use plugin.
It should make Hummingbird to not cache anything, except for the pages specified in the URL Strings exclusion list. You’ll need to put the ! symbol before each page/post slug, for example:
!login
!page1
!page2
Screenshot:
https://prnt.sc/viX9W71_IGl6
Best Regards,
Dmytro