How to programmatically configure WP Rocket's options

Heads up! This guide assumes comfort with editing PHP code. If that's not you, please ask your developer to implement it for you.

There are currently 2 possible ways to automate the configuration of WP Rocket:

  • Using the WP Rocket CLI can be a way to automate the configuration of WP Rocket.
  • Alternatively, you can modify the settings via PHP using our function update_rocket_option ()

Using update_rocket_option()

  1. To do this, you will create a PHP file and upload it to the root of your WordPress installation, where wp-load.php is located. 
  2. The format of the contents will be like this:
  3. <?php 
    // Load WordPress.
    require( 'wp-load.php' );
    if(function_exists('update_rocket_option')) {
      update_rocket_option( 'option_name', 0);
  4. option_name will be replaced with the appropriate name from the list below. Add one line for each option that you want to configure - you can add as many as needed. 
  5. Specify 0 to turn the option off, 1 to turn it on
  6. Here is an example of a configuration file which turns off LazyLoad, turns on Delay JavaScript Execution, turns on the CDN and sets the CNAME to
  7. <?php 
    // Load WordPress.
    require( 'wp-load.php' );
    if(function_exists('update_rocket_option')) {
      update_rocket_option( 'lazyload', 0);
      update_rocket_option( 'delay_js', 1);
      update_rocket_option( 'cdn', 1);
      update_rocket_option( 'cdn_cnames', [""] );
  8. Visit the file in your browser to execute the configuration.
  9. When you visit your admin, you will see that the options have been applied per your configuration file.

If you are using this to set an initial configuration, you only need to update the options which will differ from the default configuration. All others will remain at default, or unchanged from their current values. Once set, all options can be re-configured directly from the settings page. The configuration file will only be applied after being visited in your browser.

Here is a list of most WP Rocket features and their associated option names:

  • Disable Emojis: emoji
  • Optimize Google Fonts: minify_google_fonts
  • Mobile cache: cache_mobile
  • Separate cache files for mobile devices: do_caching_mobile_files
  • User Cache: cache_logged_user
  • Cache Lifespan value: purge_cron_interval. Value should be an integer, examples: 1, 8, 24, etc.
  • Cache Lifespan frequency: purge_cron_unit. Possible values are  'HOUR_IN_SECONDS' or 'DAY_IN_SECONDS'
  • Minify CSS files: minify_css
  • Load CSS Asynchronously: async_css
  • Remove Unused CSS: remove_unused_css
  • Minify JavaScript files: minify_js
  • Combine JavaScript files: minify_concatenate_js
  • Load JavaScript deferred: defer_all_js
  • Delay JavaScript execution: delay_js
  • LazyLoad for images: lazyload
  • LazyLoad for iframes: lazyload_iframes
  • LazyLoad for CSS background images: lazyload_css_bg_img
  • Replace YouTube iframe with preview image: lazyload_youtube
  • Add missing image dimensions: image_dimensions
  • Preload cache: manual_preload
  • Preload links: preload_links
  • CDN: cdn
  • CDN CNAME(s): cdn_cnames, with values such as ["", ""]
  • Varnish add-on: varnish_auto_purge
  • WebP Compatibility add-on: cache_webp

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.