Powered Cache and Powered Cache Premium have hundreds of filters and actions that let developers change what is cached, cleared, optimized and preloaded. This page lists the ones you will need most often and shows where to put your code. The complete, always up-to-date list is in the generated hook reference.
Available in: Powered Cache (free) and Powered Cache Premium
Where to find it: Full hook reference at poweredcache.github.io/docs
Where to add custom code #
Put Powered Cache customizations in a small must-use plugin. A file in wp-content/mu-plugins/ loads before regular plugins and the theme, keeps working when you switch themes, and cannot be deactivated by accident. Some hooks run before the theme loads, so code in the theme’s functions.php is too late for them, for example powered_cache_fo_disable and powered_cache_hide_license_settings.
- Create the folder
wp-content/mu-plugins/if it does not exist. - Create a file such as
powered-cache-custom.phpin it. - Add your code, starting with
<?php.
<?php
/**
* Plugin Name: Powered Cache customizations
*/
// Never cache the live scores page.
add_filter( 'powered_cache_page_cache_enable', function ( $enable ) {
if ( is_page( 'live-scores' ) ) {
return false;
}
return $enable;
} );
Filters that need a configuration rewrite #
The page cache runs before WordPress loads, so it cannot call your filters on each request. Instead, Powered Cache applies the cache rule filters when it writes its configuration file. After you add or change one of the filters marked config below, go to Powered Cache → Tools and click Fix configuration, or save the settings, so the file is rewritten. See Fix Configuration.
Most used filters #
Page cache and cache rules #
| Filter | Purpose |
|---|---|
powered_cache_page_cache_enable | Return false to skip saving the current page to the cache. Runs at the end of each request, so conditional tags such as is_page() work. |
powered_cache_rejected_uri_list | Add URLs that are never cached, like Never Cache URLs. Wildcards work. Config. |
powered_cache_rejected_cookies | Add cookies that turn off caching for a visitor. Config. |
powered_cache_vary_cookies | Add cookies that get their own cached copy of each page, for example a currency or consent cookie. Config. |
powered_cache_ignored_query_strings | Query parameters to ignore, so the page is still served from the cache. Config. |
powered_cache_cache_query_strings | Query parameters that get their own cached copy. Config. |
Cache clearing #
| Hook | Purpose |
|---|---|
powered_cache_post_related_urls (filter) | Change the list of URLs that belong to a post, such as its archives and feeds. Receives the URLs and the post ID. |
powered_cache_advanced_cache_purge_urls (filter) | Change the URLs cleared when a post is published, updated or removed. Receives the URLs and the post ID. |
powered_cache_advanced_cache_purge_post (action) | Runs after the cache of a post was cleared. Useful to clear an external cache for the same URLs. |
powered_cache_purge_all_cache (action) | Runs after Purge All Cache. |
powered_cache_flushed (action) | Runs after the whole cache directory was emptied. |
powered_cache_clean_site_cache_dir (action) | Runs after the page cache of the current site was cleared. |
File optimization and media #
| Filter | Purpose |
|---|---|
powered_cache_fo_disable | Return true to turn off file optimization for a request. Runs early: use a must-use plugin. |
powered_cache_fo_excluded_css_files | Add stylesheets to Excluded CSS Files. |
powered_cache_fo_excluded_js_files | Add scripts to Excluded JavaScript Files. |
powered_cache_defer_exclusions | Add scripts to Defer JavaScript Exclusions. |
powered_cache_delay_exclusions | Add scripts to Delay JavaScript Exclusions. |
powered_cache_lazy_load_enabled | Return false to turn off lazy loading on the current page. |
powered_cache_lazy_load_exclusions | Add entries to Lazy Load Exclusions. |
powered_cache_cdn_extensions | Change which file extensions are served from the CDN. |
Preload #
| Filter | Purpose |
|---|---|
powered_cache_preload_post_limit | How many posts automatic, scheduled and admin-bar full preloads include. Default 1000. |
powered_cache_preload_term_limit | How many terms per taxonomy those preloads include. Default 100. |
powered_cache_full_preload_urls | Change each batch of URLs discovered during a full preload. New in 4.1. |
populate_preload_queue_urls | Change the complete home page, post and archive list once per full preload. |
powered_cache_preload_url_request_args | Change the HTTP request arguments for preload requests. |
Settings and setup #
| Hook | Purpose |
|---|---|
powered_cache_settings_saved (action) | Runs after settings are saved. Receives the old and new settings. |
powered_cache_recommended_settings (filter) | Change what Apply Recommended Settings turns on. |
powered_cache_system_status_checks (filter) | Add or change checks in the Optimization Advisor. |
Premium #
| Filter | Purpose |
|---|---|
powered_cache_license_key | Supply the license key from code. A POWERED_CACHE_LICENSE_KEY constant takes priority. |
powered_cache_hide_license_settings | Show or hide the License section. Runs early: use a must-use plugin. |
powered_cache_instant_navigation_exclude_paths | Add paths that Instant Navigation never loads early. New in 4.1. |
powered_cache_instant_navigation_eagerness | Change when Instant Navigation starts loading a link. New in 4.1. |
powered_cache_sitemap_preload_list | Change the sitemaps used by Sitemap Preload. |
Clear the cache from your own code #
To clear one URL, for example after an import updates a page outside the editor, call the helper function. Check that it exists first, so your code keeps working if Powered Cache is deactivated:
if ( function_exists( '\PoweredCache\Utils\delete_page_cache' ) ) {
\PoweredCache\Utils\delete_page_cache( 'https://example.com/pricing/' );
}
With Premium, you can also clear the cache from the command line. See WP-CLI Commands.
Full hook reference #
Every filter and action, with its parameters and the version it was added in, is listed at poweredcache.github.io/docs. The reference is generated from the code, so it always matches the latest release.