List of pre_get_rocket_option_{option_name} filters
WP Rocket's pre_get_rocket_option_{option_name}
filters can be used to programmatically activate and deactivate WP Rocket's options, or to apply bulk changes to WP Rocket settings based on any conditions you apply.
Heads up! This guide is for advanced users comfortable with PHP.
How to use the filters
These filters can be used on your theme's functions.php file or as a snippet, as shown here, or using the helper plugin in this article.
For example, to activate the Delay JavaScript Execution, you can use __return_true
, like this:
add_filter( 'pre_get_rocket_option_delay_js', '__return_true' )
And, you can deactivate this feature with __return_zero
, like this:
add_filter( 'pre_get_rocket_option_delay_js', '__return_zero' );
Some of the filters are used to modify specific WP Rocket options as well. Those filters don't use the simple __return_zero
values, and instead need to use a function to apply your custom changes. Something like the following would be applied:
add_filter( 'pre_get_rocket_option_exclude_lazyload', function() { [Your custom code here] return $lazyload_exclusions; } );
List of pre_get_rocket_option filters
pre_get_rocket_option_analytics_enabled pre_get_rocket_option_async_css pre_get_rocket_option_async_css_mobile pre_get_rocket_option_automatic_cleanup_frequency pre_get_rocket_option_cache_logged_user pre_get_rocket_option_cache_mobile pre_get_rocket_option_cache_purge_pages pre_get_rocket_option_cache_query_strings pre_get_rocket_option_cache_reject_cookies pre_get_rocket_option_cache_reject_ua pre_get_rocket_option_cache_reject_uri pre_get_rocket_option_cache_ssl pre_get_rocket_option_cache_webp pre_get_rocket_option_cdn pre_get_rocket_option_cdn_cnames pre_get_rocket_option_cdn_reject_files pre_get_rocket_option_cdn_zone pre_get_rocket_option_cloudflare_api_key pre_get_rocket_option_cloudflare_auto_settings pre_get_rocket_option_cloudflare_devmode pre_get_rocket_option_cloudflare_email pre_get_rocket_option_cloudflare_old_settings pre_get_rocket_option_cloudflare_protocol_rewrite pre_get_rocket_option_cloudflare_zone_id pre_get_rocket_option_consumer_email pre_get_rocket_option_consumer_key pre_get_rocket_option_control_heartbeat pre_get_rocket_option_critical_css pre_get_rocket_option_database_all_transients pre_get_rocket_option_database_auto_drafts pre_get_rocket_option_database_optimize_tables pre_get_rocket_option_database_revisions pre_get_rocket_option_database_spam_comments pre_get_rocket_option_database_trashed_comments pre_get_rocket_option_database_trashed_posts pre_get_rocket_option_defer_all_js pre_get_rocket_option_delay_js pre_get_rocket_option_delay_js_exclusions pre_get_rocket_option_dns_prefetch pre_get_rocket_option_do_caching_mobile_files pre_get_rocket_option_do_cloudflare pre_get_rocket_option_emoji pre_get_rocket_option_exclude_css pre_get_rocket_option_exclude_defer_js pre_get_rocket_option_exclude_inline_js pre_get_rocket_option_exclude_js pre_get_rocket_option_exclude_lazyload pre_get_rocket_option_heartbeat_admin_behavior pre_get_rocket_option_heartbeat_editor_behavior pre_get_rocket_option_heartbeat_site_behavior pre_get_rocket_option_image_dimensions pre_get_rocket_option_lazyload pre_get_rocket_option_lazyload_css_bg_img pre_get_rocket_option_lazyload_iframes pre_get_rocket_option_lazyload_youtube pre_get_rocket_option_license pre_get_rocket_option_manual_preload pre_get_rocket_option_minify_concatenate_js pre_get_rocket_option_minify_css pre_get_rocket_option_minify_css_key pre_get_rocket_option_minify_google_fonts pre_get_rocket_option_minify_js pre_get_rocket_option_minify_js_key pre_get_rocket_option_optimize_css_delivery pre_get_rocket_option_optimize_css_delivery_method pre_get_rocket_option_preload_fonts pre_get_rocket_option_preload_links pre_get_rocket_option_purge_cron_interval pre_get_rocket_option_purge_cron_unit pre_get_rocket_option_remove_unused_css pre_get_rocket_option_remove_unused_css_safelist pre_get_rocket_option_schedule_automatic_cleanup pre_get_rocket_option_secret_cache_key pre_get_rocket_option_secret_key pre_get_rocket_option_sitemaps pre_get_rocket_option_sucury_waf_api_key pre_get_rocket_option_sucury_waf_cache_sync pre_get_rocket_option_varnish_auto_purge pre_get_rocket_option_version