The enable_loading_advanced_cache_dropin WordPress PHP filter allows you to control the loading of the advanced-cache.php
drop-in file.
Usage
add_filter( 'enable_loading_advanced_cache_dropin', 'your_custom_function' ); function your_custom_function( $enable_advanced_cache ) { // your custom code here return $enable_advanced_cache; }
Parameters
- $enable_advanced_cache (bool): Whether to enable loading
advanced-cache.php
(if present). Default istrue
.
More information
See WordPress Developer Resources: enable_loading_advanced_cache_dropin
Examples
Disable advanced-cache.php loading
Prevent the advanced-cache.php
file from loading.
add_filter( 'enable_loading_advanced_cache_dropin', '__return_false' );
Enable advanced-cache.php loading only on specific pages
Allow the advanced-cache.php
file to load only on specific pages by checking the current page slug.
add_filter( 'enable_loading_advanced_cache_dropin', 'load_advanced_cache_on_specific_pages' ); function load_advanced_cache_on_specific_pages( $enable_advanced_cache ) { $allowed_pages = array( 'about-us', 'contact' ); if ( in_array( get_post_field( 'post_name', get_post() ), $allowed_pages ) ) { return true; } return false; }
Enable advanced-cache.php loading for logged-in users
Allow the advanced-cache.php
file to load only for logged-in users.
add_filter( 'enable_loading_advanced_cache_dropin', 'load_advanced_cache_for_logged_in_users' ); function load_advanced_cache_for_logged_in_users( $enable_advanced_cache ) { if ( is_user_logged_in() ) { return true; } return false; }
Enable advanced-cache.php loading for a specific user role
Allow the advanced-cache.php
file to load only for users with a specific role, such as ‘administrator’.
add_filter( 'enable_loading_advanced_cache_dropin', 'load_advanced_cache_for_administrators' ); function load_advanced_cache_for_administrators( $enable_advanced_cache ) { if ( current_user_can( 'administrator' ) ) { return true; } return false; }
Disable advanced-cache.php loading on mobile devices
Prevent the advanced-cache.php
file from loading on mobile devices using the wp_is_mobile()
function.
add_filter( 'enable_loading_advanced_cache_dropin', 'disable_advanced_cache_on_mobile' ); function disable_advanced_cache_on_mobile( $enable_advanced_cache ) { if ( wp_is_mobile() ) { return false; } return true; }