Support

Find answers, guides, and tutorials to supercharge your content delivery.

WordPress Cache Enabler Plugin

Updated on September 28, 2021

The WordPress Cache Enabler plugin is a lightweight page caching plugin that creates static HTML files and stores them on your web server. This means that a static HTML file will be delivered whenever possible to provide users with the response data that would otherwise involve the resource intensive process of using the WordPress core, plugins, and database. It supports converting inline image URLs to WebP, creating a separate mobile cache, and pre-compressing cached pages with Brotli or Gzip. This simple, yet powerful plugin is easy to use, needs minimal configuration, and best of all helps improve site load time.

Installation

Installation of the WordPress Cache Enabler plugin is easy and can be done in just a few steps:

  1. Log in to your WordPress admin dashboard.
  2. In the left navigation sidebar hover over Plugins and then click Add New.
  3. Either upload the latest Cache Enabler version in .zip format, which can be directly downloaded here, or search for "Cache Enabler" and click Install Now on the plugin by KeyCDN.
  4. After the Cache Enabler plugin has been installed activate the plugin.

Cache Enabler will now be successfully installed and activated on your WordPress website. We have built this plugin to work for the majority of WordPress installations right out of the box, which means there are no required configurations or settings to make this plugin start caching your pages. However, you may want to further configure Cache Enabler to fit your needs, which can be done through the plugin settings and/or hooks.

Settings

Customizing the Cache Enabler plugin settings can be done by going to the Cache Enabler settings page. This page can be accessed by doing the following:

  1. Log in to your WordPress admin dashboard.
  2. In the left navigation sidebar hover over Settings and then click Cache Enabler.

The Cache Enabler settings page is simple and broken into two parts, Cache Behavior and Cache Exclusions. The Cache Behavior settings control the behavior of page caching, whereas the Cache Exclusions settings controls what pages should bypass the cache.

Hooks

NameTypeDescription
cache_enabler_clear_complete_cacheActionClear the site cache of a single site or all sites in a multisite network.
cache_enabler_complete_cache_clearedActionFires after the complete cache has been cleared.
cache_enabler_clear_site_cacheActionClear the site cache for the current site or of a given site.
cache_enabler_site_cache_clearedActionFires after the site cache has been cleared.
cache_enabler_clear_page_cache_by_postActionClear the page cache of a given post.
cache_enabler_clear_page_cache_by_urlActionClear the page cache of a given URL.
cache_enabler_page_cache_clearedActionFires after the page cache has been cleared.
cache_enabler_clear_expired_cacheActionClear the expired cache for the current site or of a given site.
cache_enabler_user_can_clear_cacheFilterFilters whether the current user can clear the cache.
cache_enabler_settings_before_validationFilterFilters the plugin settings before being validated and added or maybe updated.
cache_enabler_exclude_searchFilterFilters whether search queries should be excluded from the cache.
cache_enabler_bypass_cacheFilterFilters whether the cache should be bypassed.
cache_enabler_page_contents_before_storeFilterFilters the page contents before a static HTML file is created.
cache_enabler_mkdir_modeFilterFilters the mode assigned to directories on creation.
cache_enabler_minify_html_ignore_tagsFilterFilters the HTML tags to ignore during HTML minification.
cache_enabler_convert_webp_attributesFilterFilters the HTML attributes to convert during the WebP conversion.
cache_enabler_convert_webp_ignore_query_stringsFilterFilters whether inline image URLs with query strings should be ignored during the WebP conversion.
cache_enabler_page_contents_after_webp_conversionFilterFilters the page contents after the inline image URLs were maybe converted to WebP.
cache_enabler_page_cache_createdActionFires after the page cache has been created.

cache_enabler_clear_complete_cache

do_action( 'cache_enabler_clear_complete_cache' );

Clear the site cache of a single site or all sites in a multisite network.

Source

File: inc/cache_enabler.class.php

Changelog

1.6.0 - Introduced.

Example

function clear_cache_enabler_complete_cache() {

    do_action( 'cache_enabler_clear_complete_cache' );
}

cache_enabler_complete_cache_cleared

do_action( 'cache_enabler_complete_cache_cleared' );

Fires after the complete cache has been cleared.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.0 - Introduced.

Example

add_action( 'cache_enabler_complete_cache_cleared', 'on_cache_enabler_complete_cache_cleared' );

function on_cache_enabler_complete_cache_cleared() {

    // code...
}

cache_enabler_clear_site_cache

do_action( 'cache_enabler_clear_site_cache', WP_Site|int|string $site = null );

Clear the site cache for the current site or of a given site.

Parameters

$site (WP_Site|int|string) (Optional) Site instance or site blog ID. Default is the current site.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.0 - The $site parameter was added.

1.6.0 - Introduced.

Example

function clear_cache_enabler_site_cache() {

    do_action( 'cache_enabler_clear_site_cache' );
}

cache_enabler_clear_site_cache_by_blog_id

do_action( 'cache_enabler_clear_site_cache_by_blog_id', int $blog_id );
Note: This hook has been deprecated and will be removed in a future version.

Clear the site cache of a given blog ID.

Parameters

$blog_id (int) Site blog ID.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.0 - Deprecated.

1.6.0 - Introduced.

Example

$blog_id = 1;

function clear_cache_enabler_site_cache_by_blog_id( $blog_id ) {

    do_action( 'cache_enabler_clear_site_cache_by_blog_id', $blog_id );
}

cache_enabler_site_cache_cleared

do_action( 'cache_enabler_site_cache_cleared', string $site_cleared_url, int $site_cleared_id, array[] $cache_cleared_index );

Fires after the site cache has been cleared.

Parameters

$site_cleared_url (string) Full URL of the site cleared.

$site_cleared_id (int) Post ID of the site cleared.

$cache_cleared_index (array[]) Index of the cache cleared.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.8.0 - The $cache_cleared_index parameter was added.

1.6.0 - Introduced.

Example

add_action( 'cache_enabler_site_cache_cleared', 'on_cache_enabler_site_cache_cleared', 10, 3 );

function on_cache_enabler_site_cache_cleared( $site_cleared_url, $site_cleared_id, $cache_cleared_index ) {

    // code...
}

cache_enabler_clear_page_cache_by_post

do_action( 'cache_enabler_clear_page_cache_by_post', WP_Post|int|string $post );

Clear the page cache of a given post.

Parameters

$post (WP_Post|int|string) Post instance or post ID.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.0 - Introduced.

Example

$post = 1;

function clear_cache_enabler_page_cache_by_post( $post ) {

    do_action( 'cache_enabler_clear_page_cache_by_post', $post );
}

cache_enabler_clear_page_cache_by_post_id

do_action( 'cache_enabler_clear_page_cache_by_post_id', int $post_id );
Note: This hook has been deprecated and will be removed in a future version.

Clear the page cache of a given post.

Parameters

$post_id (int) Post ID.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.0 - Deprecated.

1.6.0 - Introduced.

Example

$post_id = 1;

function clear_cache_enabler_page_cache_by_post_id( $post_id ) {

    do_action( 'cache_enabler_clear_page_cache_by_post_id', $post_id );
}

cache_enabler_clear_page_cache_by_url

do_action( 'cache_enabler_clear_page_cache_by_url', string $url );

Clear the page cache of a given URL.

Parameters

$url (string) URL to a cached page (with or without scheme, wildcard path, and query string).

Source

File: inc/cache_enabler.class.php

Changelog

1.6.0 - Introduced.

Example

/**
 * The URL being cleared does not require a scheme, so using
 * 'www.example.com/blog/' instead will end in the same result. Appending an '*'
 * adds wildcard cache clearing. For example, 'www.example.com/blog/*' will clear
 * the page and all subpages, whereas 'www.example.com/blog/how-to-*' will only
 * clear subpages that begin with 'www.example.com/blog/how-to-'. Cache iterator
 * arguments are supported and can be passed through a query string.
 */
$url = 'https://www.example.com/blog/';

function clear_cache_enabler_page_cache_by_url( $url ) {

    do_action( 'cache_enabler_clear_page_cache_by_url', $url );
}

cache_enabler_page_cache_cleared

do_action( 'cache_enabler_page_cache_cleared', string $page_cleared_url, int $page_cleared_id, array[] $cache_cleared_index );

Fires after the page cache has been cleared.

Parameters

$page_cleared_url (string) Full URL of the page cleared.

$page_cleared_id (int) Post ID of the page cleared.

$cache_cleared_index (array[]) Index of the cache cleared.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.8.0 - The $cache_cleared_index parameter was added.

1.6.0 - Introduced.

Example

add_action( 'cache_enabler_page_cache_cleared', 'on_cache_enabler_page_cache_cleared', 10, 3 );

function on_cache_enabler_page_cache_cleared( $page_cleared_url, $page_cleared_id, $cache_cleared_index ) {

    // code...
}

cache_enabler_clear_expired_cache

do_action( 'cache_enabler_clear_expired_cache', WP_Site|int|string $site = null );

Clear the expired cache for the current site or of a given site.

Parameters

$site (WP_Site|int|string) (Optional) Site instance or site blog ID. Default is the current site.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.0 - Introduced.

Example

function clear_cache_enabler_expired_cache() {

    do_action( 'cache_enabler_clear_expired_cache' );
}

cache_enabler_user_can_clear_cache

apply_filters( 'cache_enabler_user_can_clear_cache', bool $can_clear_cache = current_user_can( 'manage_options' ) );

Filters whether the current user can clear the cache.

Parameters

$can_clear_cache (bool) Whether the current user can clear the cache. Default is whether the current user has the 'manage_options' capability.

Source

File: inc/cache_enabler.class.php

Changelog

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_user_can_clear_cache', 'current_user_can_edit_posts' );

function current_user_can_edit_posts() {

    return current_user_can( 'edit_posts' );
}

cache_enabler_settings_before_validation

apply_filters( 'cache_enabler_settings_before_validation', array $settings );

Filters the plugin settings before being validated and added or maybe updated.

This can be an empty array or not contain all plugin settings. It will depend on if the plugin was just installed, the plugin version being upgraded from, or the form submitted in the plugin settings page. The plugin system settings are protected and cannot be overwritten.

Parameters

$settings (array) Plugin settings.

Source

File: inc/cache_enabler.class.php

Changelog

1.8.6 - Introduced.

Example

add_filter( 'cache_enabler_settings_before_validation', 'filter_cache_enabler_settings_before_validation' );

function filter_cache_enabler_settings_before_validation( $settings ) {

    $forced_settings = array(
        'convert_image_urls_to_webp' => 1,
        'compress_cache'             => 1,
        'minify_html'                => 1,
        'minify_inline_css_js'       => 1,
    );

    $settings = wp_parse_args( $forced_settings, $settings );

    return $settings;
}

apply_filters( 'cache_enabler_exclude_search', bool $exclude_search = is_search() );

Filters whether search queries should be excluded from the cache.

This requires pretty search URLs. For example, https://example.com/search/query/ instead of https://example.com/?s=query. The search cache will not be automatically cleared.

Parameters

$exclude_search (bool) True if search queries should be excluded from the cache, false if not. Default is the value returned by is_search().

Source

File: inc/cache_enabler_engine.class.php

Changelog

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_exclude_search', '__return_false' );

cache_enabler_bypass_cache

apply_filters( 'cache_enabler_bypass_cache', bool $bypass_cache = Cache_Enabler_Engine::is_excluded() );

Filters whether the cache should be bypassed.

Parameters

$bypass_cache (bool) True if the cache should be bypassed, false if not. Default is the value returned by Cache_Enabler_Engine::is_excluded().

Source

File: inc/cache_enabler_engine.class.php

Changelog

1.8.0 - The default value for $bypass_cache was updated.

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_bypass_cache', 'filter_cache_enabler_bypass_cache' );

function filter_cache_enabler_bypass_cache( $bypass_cache ) {

    $post_type = get_post_type();

    if ( $post_type === 'custom_post_type' ) {
        $bypass_cache = true;
    }

    return $bypass_cache;
}

cache_enabler_page_contents_before_store

apply_filters( 'cache_enabler_page_contents_before_store', string $page_contents );

Filters the page contents before a static HTML file is created.

Parameters

$page_contents (string) Page contents from the cache engine as raw HTML.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_page_contents_before_store', 'filter_cache_enabler_page_contents_before_store' );

function filter_cache_enabler_page_contents_before_store( $page_contents ) {

    // code...
}

cache_enabler_mkdir_mode

apply_filters( 'cache_enabler_mkdir_mode', int $mode = 0755 );

Filters the mode assigned to directories on creation.

Parameters

$mode (int) Mode that defines the access permissions for the created directory. The mode must be an octal number, which means it should have a leading zero. Default is 0755.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.7.2 - Introduced.

Example

add_filter( 'cache_enabler_mkdir_mode', 'filter_cache_enabler_mkdir_mode' );

function filter_cache_enabler_mkdir_mode( $mode ) {

    return 0775;
}

cache_enabler_minify_html_ignore_tags

apply_filters( 'cache_enabler_minify_html_ignore_tags', string[] $ignore_tags = array( 'textarea', 'pre', 'code' ) );

Filters the HTML tags to ignore during HTML minification.

Parameters

$ignore_tags (string[]) The names of HTML tags to ignore. Default are textarea, pre, and code.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_minify_html_ignore_tags', 'filter_cache_enabler_minify_html_ignore_tags' );

function filter_cache_enabler_minify_html_ignore_tags( $ignore_tags ) {

    $ignore_tags[] = 'canvas'; // Also ignore the HTML <canvas> element.

    return $ignore_tags;
}

cache_enabler_convert_webp_attributes

apply_filters( 'cache_enabler_convert_webp_attributes', string[] $attributes = array( 'src', 'srcset', 'data-[^=]+' ) );

Filters the HTML attributes to convert during the WebP conversion.

Parameters

$attributes (string[]) HTML attributes to convert during the WebP conversion. Default are src, srcset, and data-*.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.1 - Introduced.

Example

add_filter( 'cache_enabler_convert_webp_attributes', 'filter_cache_enabler_convert_webp_attributes' );

function filter_cache_enabler_convert_webp_attributes( $attributes ) {

    $attributes[] = 'href'; // Also convert href attributes.

    return $attributes;
}

cache_enabler_convert_webp_ignore_query_strings

apply_filters( 'cache_enabler_convert_webp_ignore_query_strings', bool $ignore_query_strings = true );

Filters whether inline image URLs with query strings should be ignored during the WebP conversion.

Parameters

$ignore_query_strings (bool) True if inline image URLs with query strings should be ignored during the WebP conversion, false if not. Default true.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.1 - Introduced.

Example

add_filter( 'cache_enabler_convert_webp_ignore_query_strings', '__return_false' );

cache_enabler_page_contents_after_webp_conversion

apply_filters( 'cache_enabler_page_contents_after_webp_conversion', string $page_contents );

Filters the page contents after the inline image URLs were maybe converted to WebP.

Parameters

$page_contents (string) Page contents from the cache engine as raw HTML.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.6.0 - Introduced.

Example

add_filter( 'cache_enabler_page_contents_after_webp_conversion', 'filter_cache_enabler_page_contents_after_webp_conversion' );

function filter_cache_enabler_page_contents_after_webp_conversion( $page_contents ) {

    // code...
}

cache_enabler_page_cache_created

apply_filters( 'cache_enabler_page_cache_created', string $page_created_url, int $page_created_id, array[] $cache_created_index );

Fires after the page cache has been created.

Parameters

$page_created_url (string) Full URL of the page created.

$page_created_id (int) Post ID of the page created.

$cache_created_index (array[]) Index of the cache created.

Source

File: inc/cache_enabler_disk.class.php

Changelog

1.8.0 - Introduced.

Example

add_action( 'cache_enabler_page_cache_created', 'on_cache_enabler_page_cache_created', 10, 3 );

function on_cache_enabler_page_cache_created( $page_created_url, $page_created_id, $cache_created_index ) {

    // code...
}

WP-CLI

Interact with Cache Enabler from the command line by either clearing the cache or updating the settings. This can be done through WP-CLI with the cache-enabler and option commands.

cache-enabler

Clear the cache with the cache-enabler command and clear subcommand.

Options

--ids=<id>
Clear the cache of a given post ID. Separate multiple IDs with commas.

--urls=<url>
Clear the cache of a given URL. The URL can be with or without a scheme, wildcard path, and query string. Separate multiple URLs with commas.

--sites=<site>
Clear the cache of a given blog ID. Separate multiple blog IDs with commas.

Examples

# Clear all pages cache.
$ wp cache-enabler clear

# Clear the page cache of post IDs 1, 2, and 3.
$ wp cache-enabler clear --ids=1,2,3

# Clear the page cache of https://www.example.com/about-us/.
$ wp cache-enabler clear --urls=www.example.com/about-us/

# Clear the page cache of any URL that starts with https://www.example.com/blog/how-to-.
$ wp cache-enabler clear --urls=www.example.com/blog/how-to-*
Success: Page cache cleared.

# Clear the page cache of https://www.example.com/blog/ and all of its subpages.
$ wp cache-enabler clear --urls=www.example.com/blog/*
Success: Page cache cleared.

# Clear the page cache of sites with blog IDs 1, 2, and 3.
$ wp cache-enabler clear --sites=1,2,3
Success: Sites cache cleared.

option

Update the settings with the option command and update subcommand.

ParameterDescriptionValue
versionPlugin version.string
use_trailing_slashesWhether the permalink structure has a trailing slash set.0 or 1
int
permalink_structure
deprecated
Whether the permalink structure has a trailing slash set.has_trailing_slash, no_trailing_slash, or plain
string
cache_expiresWhether the cached pages expire.0 or 1
int
cache_expiry_timeCache expiry measured in hours.int
clear_site_cache_on_saved_postClear the site cache if any post type has been published, updated, or trashed (instead of the post cache).0 or 1
int
clear_site_cache_on_saved_commentClear the site cache if a comment has been posted, updated, spammed, or trashed (instead of the comment cache).0 or 1
int
clear_site_cache_on_saved_termClear the site cache if a term has been added, updated, or deleted (instead of the term cache).0 or 1
int
clear_site_cache_on_saved_userClear the site cache if a user has been added, updated, or deleted (instead of the user cache).0 or 1
int
clear_site_cache_on_changed_pluginClear the site cache if a plugin has been activated or deactivated.0 or 1
int
convert_image_urls_to_webpCreate a cached version for WebP support. Convert your images to WebP with Optimus.0 or 1
int
mobile_cacheCreate a cached version for mobile devices.0 or 1
int
compress_cacheCreate a cached version pre-compressed with Brotli (if supported) or Gzip.0 or 1
int
minify_htmlMinify HTML in cached pages.0 or 1
int
minify_inline_css_jsMinify inline CSS and JavaScript when minifying HTML.0 or 1
int
excluded_post_idsPost IDs separated by a , that should bypass the cache.string
excluded_page_pathsA regex matching page paths that should bypass the cache.string
excluded_query_stringsA regex matching query strings that should bypass the cache.string
excluded_cookiesA regex matching cookies that should bypass the cache.string

Example

# Enable WebP and Gzip/Brotli versions with full HTML minification.
$ wp option update cache_enabler \
'{
    "version": "1.8.0",
    "use_trailing_slashes": 1,
    "permalink_structure": "has_trailing_slash",
    "cache_expires": 0,
    "cache_expiry_time": 0,
    "clear_site_cache_on_saved_post": 0,
    "clear_site_cache_on_saved_comment": 0,
    "clear_site_cache_on_saved_term": 0,
    "clear_site_cache_on_saved_user": 0,
    "clear_site_cache_on_changed_plugin": 0,
    "convert_image_urls_to_webp": 1,
    "mobile_cache": 0,
    "compress_cache": 1,
    "minify_html": 1,
    "minify_inline_css_js": 1,
    "excluded_post_ids": "",
    "excluded_page_paths": "",
    "excluded_query_strings": "",
    "excluded_cookies": ""
}' \
--format=json

Advanced configuration

A more advanced configuration can be implemented to bypass PHP entirely for even faster delivery of cached pages. The following configuration snippets can be implemented on Apache or Nginx servers. The advanced configuration snippets should only be used by those who are experienced in modifying server configuration files. Furthermore, the default Cache Enabler setup should satisfy the majority of use-cases.

Note: This configuration is optional and is not required in order to use the Cache Enabler plugin. It is only an optional configuration for those who want to entirely bypass PHP if a static HTML file exists. This configuration will not take into account the cached page expiration and some exclusion settings.

Apache

Add the following snippet before the # BEGIN WordPress section in your .htaccess file if you are using Apache 2.3.9 or later. Uncomment any cache keys that you need to use based on your Cache Enabler settings.

If you have installed WordPress in a subdirectory the CE_CACHE_DIR variable needs to be adjusted accordingly. For example, http://www.example.com/blog would require a change from CE_CACHE_DIR=/wp-content/cache/cache-enabler to CE_CACHE_DIR=/blog/wp-content/cache/cache-enabler.

# BEGIN Cache Enabler

<IfModule mod_rewrite.c>
    <IfModule mod_setenvif.c>
        RewriteEngine On
        RewriteBase /

        # cache directory
        SetEnvIf Host ^ CE_CACHE_DIR=/wp-content/cache/cache-enabler

        # default cache keys
        SetEnvIf Host ^ CE_CACHE_KEY_SCHEME http-
        SetEnvIf Host ^ CE_CACHE_KEY_DEVICE
        SetEnvIf Host ^ CE_CACHE_KEY_WEBP
        SetEnvIf Host ^ CE_CACHE_KEY_COMPRESSION

        # scheme cache key
        RewriteCond %{HTTPS} ^(on|1)$ [OR]
        RewriteCond %{SERVER_PORT} =443 [OR]
        RewriteCond %{HTTP:X-Forwarded-Proto} =https [OR]
        RewriteCond %{HTTP:X-Forwarded-Scheme} =https
        RewriteRule ^ - [E=CE_CACHE_KEY_SCHEME:https-]

        # device cache key
        # SetEnvIf User-Agent "(Mobile|Android|Silk/|Kindle|BlackBerry|Opera Mini|Opera Mobi)" CE_CACHE_KEY_DEVICE=-mobile

        # webp cache key
        # SetEnvIf Accept image/webp CE_CACHE_KEY_WEBP=-webp

        # compression cache key
        # <IfModule mod_mime.c>
        #     SetEnvIf Accept-Encoding gzip CE_CACHE_KEY_COMPRESSION=.gz
        #     AddType text/html .gz
        #     AddEncoding gzip .gz
        # </IfModule>

        # get cache file
        SetEnvIf Host ^ CE_CACHE_FILE_DIR=%{ENV:CE_CACHE_DIR}/%{HTTP_HOST}%{REQUEST_URI}
        SetEnvIf Host ^ CE_CACHE_FILE_NAME=%{ENV:CE_CACHE_KEY_SCHEME}index%{ENV:CE_CACHE_KEY_DEVICE}%{ENV:CE_CACHE_KEY_WEBP}.html%{ENV:CE_CACHE_KEY_COMPRESSION}
        SetEnvIf Host ^ CE_CACHE_FILE=%{ENV:CE_CACHE_FILE_DIR}/%{ENV:CE_CACHE_FILE_NAME}

        # check if cache file exists
        RewriteCond %{DOCUMENT_ROOT}%{ENV:CE_CACHE_FILE} -f

        # check request method
        RewriteCond %{REQUEST_METHOD} =GET

        # check permalink structure has trailing slash
        RewriteCond %{REQUEST_URI} /[^\./\?]+(\?.*)?$
        # check permalink structure has no trailing slash
        # RewriteCond %{REQUEST_URI} /[^\./\?]+/(\?.*)?$

        # check excluded query strings
        RewriteCond %{QUERY_STRING} !^(?!(fbclid|ref|mc_(cid|eid)|utm_(source|medium|campaign|term|content|expid)|gclid|fb_(action_ids|action_types|source)|age-verified|usqp|cn-reloaded|_ga|_ke)).+$

        # check excluded cookies
        RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_

        # deliver cache file
        RewriteRule ^ %{ENV:CE_CACHE_FILE} [L]
    </IfModule>
</IfModule>

# END Cache Enabler

Nginx

Add the following snippet to your Nginx configuration file. Uncomment any cache keys that you need to use based on your Cache Enabler settings.

If you have installed WordPress in a subdirectory the $ce_cache_dir variable needs to be adjusted accordingly. For example, http://www.example.com/blog would require a change from /wp-content/cache/cache-enabler to /blog/wp-content/cache/cache-enabler. Further, using a subdirectory may also require that the location block be updated to contain the subdirectory.

server {

    ...

    # cache directory
    set $ce_cache_dir '/wp-content/cache/cache-enabler';

    # default cache keys
    set $ce_cache_key_scheme      'http-';
    set $ce_cache_key_device      '';
    set $ce_cache_key_webp        '';
    set $ce_cache_key_compression '';

    # scheme cache key
    if ( $scheme = https ) {
        set $ce_cache_key_scheme 'https-';
    }
    # if ( $server_port = 443 ) {
    #     set $ce_cache_key_scheme 'https-';
    # }
    # if ( $http_x_forwarded_proto = https ) {
    #     set $ce_cache_key_scheme 'https-';
    # }
    # if ( $http_x_forwarded_scheme = https ) {
    #     set $ce_cache_key_scheme 'https-';
    # }

    # device cache key
    # if ( $http_user_agent ~ '(Mobile|Android|Silk/|Kindle|BlackBerry|Opera Mini|Opera Mobi)' ) {
    #    set $ce_cache_key_device '-mobile';
    # }

    # webp cache key
    # if ( $http_accept ~ image/webp ) {
    #     set $ce_cache_key_webp '-webp';
    # }

    # compression cache key
    # if ( $http_accept_encoding ~ gzip ) {
    #     set $ce_cache_key_compression '.gz';
    # }

    # get cache file
    set $ce_cache_file_dir  ${ce_cache_dir}/${http_host}${request_uri};
    set $ce_cache_file_name ${ce_cache_key_scheme}index${ce_cache_key_device}${ce_cache_key_webp}.html${ce_cache_key_compression};
    set $ce_cache_file      ${ce_cache_file_dir}/${ce_cache_file_name};

    location / {
        error_page 405 = @fallback;
        recursive_error_pages on;

        # check request method
        if ( $request_method != GET ) {
            return 405;
        }

        # check permalink structure has trailing slash
        if ( $request_uri !~ /[^\./\?]+(\?.*)?$ ) {
            return 405;
        }
        # check permalink structure has no trailing slash
        # if ( $request_uri !~ /[^\./\?]+/(\?.*)?$ ) {
        #    return 405;
        # }

        # check excluded query strings
        if ( $query_string ~ ^(?!(fbclid|ref|mc_(cid|eid)|utm_(source|medium|campaign|term|content|expid)|gclid|fb_(action_ids|action_types|source)|age-verified|usqp|cn-reloaded|_ga|_ke)).+$ ) {
            return 405;
        }

        # check excluded cookies
        if ( $http_cookie ~ (wp-postpass|wordpress_logged_in|comment_author)_ ) {
            return 405;
        }

        # deliver cache file if it exists
        try_files $ce_cache_file @fallback;
    }

    location @fallback {
        try_files $uri $uri/ /index.php?$args;
    }

    ...

}

FAQ

Find answers to commonly asked questions about Cache Enabler. Still have questions? Open a new topic in the WordPress Support Forums and we would be happy to help.

How can I check if Cache Enabler is working on my site?

You can quickly verify that the Cache Enabler is delivering a cached version of a specific page by logging out of your WordPress installation and checking the bottom of your page source for the Cache Enabler HTML comment, for example:

<!-- Cache Enabler by KeyCDN @ Wed, 24 Mar 2021 00:00:00 GMT (https-index-webp.html.gz) -->

Alternatively, if the advanced configuration is not used check the response headers of the HTML page for X-Cache-Handler: cache-enabler-engine.

What is performed when Cache Enabler is activated?

Upon activation, Cache Enabler will first setup the backend by adding or updating the database. Next, it will create the advanced-cache.php file to drop in the wp-content directory. As of version 1.8.0, this file is based on the wp-content/plugins/cache-enabler/advanced-cache.php file. Lastly, it will add the following snippet to the wp-config.php file if the WP_CACHE constant is not found and the installation is using the default config file:

/** Enables page caching for Cache Enabler. */
if ( ! defined( 'WP_CACHE' ) ) {
    define( 'WP_CACHE', true );
}
Note: Cache Enabler requires the wp-content/advanced-cache.php drop-in and the WP_CACHE constant defined as a truthy value in order to cache and deliver pages.

What is performed when Cache Enabler is deactivated?

Upon deactivation, Cache Enabler deletes the settings and advanced-cache.php files and then maybe unsets the WP_CACHE constant in the wp-config.php file. The site cache is then cleared and the WP-Cron events unscheduled.

What is performed when Cache Enabler is uninstalled?

Upon uninstallation, Cache Enabler will delete the single database option that was added or updated during the initial plugin activation along with any transients.

What happens when any post type is published, updated, or trashed?

By default, when any post type is published, updated, or trashed the post cache will be cleared. This will be the page itself, including the pagination if applicable, and any other related pages, such as archive pages (e.g. post type, terms, author, and date). This ensures pages that will contain the new page or pages that already contain an existing page are cleared. The ability to clear the site cache instead is possible through the available Cache Enabler clearing setting.

Can I clear the cache of a specific page?

Yes. You can clear the cache of a specific page by going to that page and clicking the "Clear Page Cache" button in the WordPress admin bar.

How does the WebP cached version work?

Cache Enabler parses the page contents and replaces inline image URLs with the WebP formatted image if it exists. This will work for images with the extension replaced, such as example.webp, or images with the extension appended, such as example.jpg.webp. This page is then cached separately and is delivered when accepted and the cached page with the default format(s) will be delivered when not.

How can I convert my images to WebP?

To convert your images to WebP, use the Cache Enabler plugin in conjunction with the Optimus image optimizer plugin.

How do I use Cache Enabler on a multisite network?

Using the Cache Enabler plugin on a multisite network is quite straightforward. Once the plugin is installed you can either network activate it and it will start working for each site in the network, or you can activate Cache Enabler on each site individually that you want it running on. The cache and settings are configured to work individually for each site. Therefore, you can clear the cache on site 1, while site 2 and 3 will retain their cache.

Network settings are not currently available but we intend on introducing this in future (#123).

No. Cache Enabler does not work with default permalinks.

Does Cache Enabler cache query strings?

No. Cache Enabler does not currently cache query strings as a separate version.

Does Cache Enabler work with mobile themes if the desktop and mobile versions are different?

Yes. Cache Enabler has the ability to create a separate mobile cache.

Will cached page expiration still work if the advanced configuration is used?

Yes. As of version 1.8.0, Cache Enabler will automatically schedule an hourly WP-Cron event that clears the expired cache.

How can I verify if the advanced configuration is bypassing PHP?

By adding the advanced configuration snippet to your server you have the ability to bypass PHP in order to retrieve the static HTML file that was created by the WordPress Cache Enabler plugin. In order to ensure that you are in fact bypassing PHP after you've added the snippet, open up your developer tools, navigate to the Network panel and select the HTML file of your page.

If you've added the advanced configuration snippet successfully, the X-Cache-Handler: cache-enabler-engine response header will no longer be set, which means the Cache Enabler engine, which is powered by PHP, is no longer handling the delivery. If this response header is not present and the Cache Enabler HTML comment is still in the page source then your advanced configuration is properly implemented.

How can a cached version be pre-compressed with Brotli?

All WordPress installations have the ability to pre-compress cached pages with Gzip because it is a native compression module included in PHP. The same can't be said for Brotli. To have this functionality in Cache Enabler the Brotli Extension for PHP is required and the site must be delivered through HTTPS (because Brotli requires HTTPS). Once this extension has been added and a page is requested through HTTPS, Cache Enabler will be able to create a cached version pre-compressed with Brotli. This compression method takes precedence over Gzip if both are accepted by the client.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more