### WP Rocket CLI Usage Examples Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Practical examples demonstrating how to use WP Rocket CLI commands. ```APIDOC ## Usage examples # Using your terminal navigate in the root folder of your WordPress installation, and type the command that corresponds to the action you’d like to be performed. **Clear the whole cache** ` wp rocket clean ` At the prompt, type `y` to confirm cache clearing. If you want to clear the cache without confirmation, append the `--confirm` flag. ` wp rocket clean --confirm` Note that this command will not clear the cache for Varnish. **Export WP Rocket settings** ` wp rocket export ` **Import WP Rocket settings** ` wp rocket import --file=wp-rocket-settings-2021-03-15-604ed873558a0.json` Alternatively, the settings file can be imported from a URL: ` wp rocket import --file=https://example.com/wp-rocket-settings.json ` ``` -------------------------------- ### Install Composer Dependencies Source: https://docs.wp-rocket.me/article/1301-wp-rocket-installation-from-github-using-composer Navigate to the WP Rocket plugin directory and run this command to install necessary third-party libraries via Composer. The --no-dev and --no-scripts flags optimize the installation for production. ```bash composer install --no-dev --no-scripts ``` -------------------------------- ### WP Rocket CLI Installation Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Instructions for installing the WP Rocket CLI using WP-CLI. ```APIDOC ## WP Rocket CLI Installation **WP-CLI v0.23.0 or later** In the command line enter the following: `wp package install wp-media/wp-rocket-cli:trunk` If all goes well, you’ll see this: **WP-CLI prior to v0.23.0 - Manual installation** 1. Download the package from here: https://github.com/wp-media/wp-rocket-cli/archive/trunk.zip 2. Upload the file to your server. 3. Using the command line, navigate to the folder you uploaded the file in step 1. 4. Run the following command: ` wp package install wp-rocket-cli-trunk.zip ` ``` -------------------------------- ### Manual Installation of WP Rocket CLI (Older WP-CLI) Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Manually install the WP Rocket CLI for WP-CLI versions prior to 0.23.0. This involves downloading, uploading, and then installing the zip file. ```bash wp package install wp-rocket-cli-trunk.zip ``` -------------------------------- ### Example URL with Multiple Ignored Parameters Source: https://docs.wp-rocket.me/article/971-caching-query-strings This example shows a URL with multiple query string parameters, all of which are on the ignored list. The page will be cached. ```text example.com/page/?utm_source=this&utm_campaign=that&utm_medium=theother ``` -------------------------------- ### Example URL with Multiple Query String Parameters Source: https://docs.wp-rocket.me/article/971-caching-query-strings This example shows a URL with multiple query string parameters. If 'country' is a cached parameter, this URL will be cached. ```text example.com/page/?country=italy&wine=red ``` -------------------------------- ### Example Dynamic Filename Source: https://docs.wp-rocket.me/article/132-excluding-dynamic-filenames This is an example of a dynamically changing filename for a CSS file, where the numeric part varies. ```text style-12345678.css ``` -------------------------------- ### Original CSS link example Source: https://docs.wp-rocket.me/article/1266-optimize-css-delivery This is an example of a standard CSS link before WP Rocket's Load CSS Asynchronously modifies it. ```html ``` -------------------------------- ### Install ngx_brotli module on Debian and Ubuntu Source: https://docs.wp-rocket.me/article/1403-enable-text-compression Installs the nginx-plus-module-brotli package using apt-get. This is for Debian-based systems. ```bash $ apt-get install nginx-plus-module-brotli ``` -------------------------------- ### Example URL with Query Parameter Source: https://docs.wp-rocket.me/article/1131-resolving-issues-with-css-minify-combine Append `?nowprocket` to a URL to bypass WP Rocket and inspect CSS files. ```text example.com/about?nowprocket ``` -------------------------------- ### Another Dynamic Filename Example Source: https://docs.wp-rocket.me/article/132-excluding-dynamic-filenames This demonstrates a different dynamic filename structure, including a version query parameter. ```text media-07f3e342a4.css?v=2.3.5 custom-07f3e342a4.css?v=2.3.5 main-07f3e342a4.css?v=2.3.5 ``` -------------------------------- ### Example Cron Log Output Source: https://docs.wp-rocket.me/article/1811-how-to-check-if-cron-is-running-correctly This is an example of what the 'cron.log' file might look like, showing different types of cron triggers and their timestamps. Consistent 5-minute intervals indicate correct operation. ```log [2022-11-15 20:00:00] Cron: Triggered by the server [2022-11-15 20:01:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:02:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:05:00] Cron: Triggered by the server [2022-11-15 20:06:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:07:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:10:00] Cron: Wget/1.14 (linux-gnu) [2022-11-15 20:13:32] Cron: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) [2022-11-15 20:15:00] Cron: Triggered by the server [2022-11-15 20:16:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:17:00] Cron: WordPress/6.0.2; https://example.com/ [2022-11-15 20:20:00] Cron: Triggered by the server ``` -------------------------------- ### Uncached Page URL Example Source: https://docs.wp-rocket.me/article/1104-excluding-inline-js-from-combine This is an example of a URL used to load an uncached, unminified version of a page. Appending '?nowprocket' to the URL is necessary for finding original file URLs during troubleshooting. ```url https://example.com/?nowprocket ``` ```url https://example.com/some-page/?nowprocket ``` -------------------------------- ### Example URL with Query String Source: https://docs.wp-rocket.me/article/971-caching-query-strings This is an example of a URL containing a query string, which WP Rocket does not cache by default. ```text example.com/page/?country=italy ``` -------------------------------- ### Dedicated Caching Example Source: https://docs.wp-rocket.me/article/971-caching-query-strings This example illustrates how WP Rocket creates separate cache files for different values of a 'lang' query string parameter. ```text example.com/about-us/?lang=english example.com/about-us/?lang=french // will create a dedicated cache file for their parameter/value pairs: ?lang=english ?lang=french ``` -------------------------------- ### Install ngx_brotli module on SLES 15 Source: https://docs.wp-rocket.me/article/1403-enable-text-compression Installs the nginx-plus-module-brotli package using zypper. This is for SUSE Linux Enterprise Server. ```bash $ zypper install nginx-plus-module-brotli ``` -------------------------------- ### Example: Custom Redirection Rule Source: https://docs.wp-rocket.me/article/614-adding-custom-rules-to-the-htaccess-file An example of a custom redirection rule that can be added to the helper plugin. This shows how to redirect an old URL to a new one. ```apache Redirect 301 /old-url.html https://yourdomain.com/new-url.html ``` -------------------------------- ### Compatible YouTube iframe Markup Example Source: https://docs.wp-rocket.me/article/1488-how-to-check-if-replace-youtube-iframe-with-preview-image-feature-is-working This is an example of the HTML markup WP Rocket looks for to apply the Replace YouTube iframe with preview image feature. It must contain an iframe with a YouTube URL in the 'src' attribute. ```html ``` -------------------------------- ### Install ngx_brotli module on Amazon Linux, CentOS, Oracle Linux, RHEL Source: https://docs.wp-rocket.me/article/1403-enable-text-compression Installs the nginx-plus-module-brotli package using yum. This is for systems using the YUM package manager. ```bash $ yum install nginx-plus-module-brotli ``` -------------------------------- ### Troubleshooting WP-CLI Memory Issues Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Guidance on resolving memory limit errors during WP Rocket CLI installation. ```APIDOC ## Troubleshooting # **WP-CLI ran out of memory** If you come across memory issues during installation you can either change the `memory_limit` in the `php.ini` or do the change "on the fly": ` php -d memory_limit=512M "$(which wp)" package install wp-media/wp-rocket-cli ` **Reference:** https://make.wordpress.org/cli/handbook/guides/common-issues/#php-fatal-error-allowed-memory-size-of-999999-bytes-exhausted-tried-to-allocate-99-bytes ``` -------------------------------- ### HTML Before Compression Source: https://docs.wp-rocket.me/article/1403-enable-text-compression This is an example of an HTML file before any compression is applied. It shows the original character count. ```html
...
``` -------------------------------- ### Multisite Cron Setup Script Source: https://docs.wp-rocket.me/article/1279-cron-and-wp-rocket This PHP script is designed for WordPress Multisite installations. It iterates through all sites in the network, triggering the wp-cron.php for each one. It requires 'wp-load.php' to be accessible. ```php blog_id); switch_to_blog( $site->blog_id ); wp_suspend_cache_addition(true); $command = $site_url.'/wp-cron.php?doing_wp_cron'; wp_remote_get( $command ); wp_suspend_cache_addition(false); restore_current_blog(); sleep(3); } } ``` -------------------------------- ### Example CSS File Paths Source: https://docs.wp-rocket.me/article/1350-css-minify-combine Illustrates the original and minified paths for CSS files, showing how WP Rocket stores optimized versions and uses a timestamp for cache busting. ```text Original file: https://example.com/wp-content/themes/twentytwenty/style.css?ver=1.5 Minified file: https://example.com/wp-content/cache/min/1/wp-content/themes/twentytwenty/style.css?ver=1614629992 ``` -------------------------------- ### Set up Server Cron Job with WGET Source: https://docs.wp-rocket.me/article/1279-cron-and-wp-rocket This command can be used in your server's cron job setup to trigger the WordPress cron job. Replace 'example.com' with your actual domain. It runs quietly and discards output. ```bash wget -q -O - https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1 ``` -------------------------------- ### Install WP Rocket CLI Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Install the WP Rocket CLI using WP-CLI. This command is for versions 0.23.0 or later. ```bash wp package install wp-media/wp-rocket-cli:trunk ``` -------------------------------- ### Example of excluding font by URL Source: https://docs.wp-rocket.me/article/1847-self-host-google-fonts This example demonstrates how to exclude a specific Google Fonts CSS file URL from being self-hosted. ```php add_filter( 'rocket_exclude_locally_host_fonts', function( $exclusions ) { $exclusions[] = 'https://fonts.googleapis.com/css2?family=Roboto&display=swap'; return $exclusions; }); ``` -------------------------------- ### Example of excluding font by attribute Source: https://docs.wp-rocket.me/article/1847-self-host-google-fonts This example shows how to exclude a font from self-hosting by using its HTML ID attribute, 'testRobo'. ```php add_filter( 'rocket_exclude_locally_host_fonts', function( $exclusions ) { $exclusions[] = 'testRobo'; return $exclusions; }); ``` -------------------------------- ### Example of excluding 'Roboto' font family Source: https://docs.wp-rocket.me/article/1847-self-host-google-fonts This example demonstrates how to exclude the 'Roboto' font family from being self-hosted by WP Rocket. ```php add_filter( 'rocket_exclude_locally_host_fonts', function( $exclusions ) { $exclusions[] = 'family=Roboto'; return $exclusions; }); ``` -------------------------------- ### Markup for Preconnect hint Source: https://docs.wp-rocket.me/article/1869-preconnect-to-external-domains This is the resulting markup when the 'preconnect' hint is used instead of 'dns-prefetch'. ```html ``` -------------------------------- ### Import WP Rocket Settings from File Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Imports WP Rocket settings from a local JSON file. ```bash wp rocket import --file=wp-rocket-settings-2021-03-15-604ed873558a0.json ``` -------------------------------- ### Example of Google Fonts file path Source: https://docs.wp-rocket.me/article/1847-self-host-google-fonts This is an example of a Google Fonts font file path when loaded from Google's servers. ```html https://fonts.gstatic.com/s/caudex/v17/hash.woff2 ``` -------------------------------- ### Configure Multiple WP Rocket Options Source: https://docs.wp-rocket.me/article/1677-how-to-programmatically-configure-wp-rocket-options Example of a PHP configuration file that disables LazyLoad, enables Delay JavaScript Execution and CDN, and sets the CDN CNAME. Visit this file in your browser to apply the settings. ```php ] ``` -------------------------------- ### Example of Google Fonts CSS path Source: https://docs.wp-rocket.me/article/1847-self-host-google-fonts This is an example of how a Google Fonts CSS file path appears when loaded from Google's CDN. ```html ``` -------------------------------- ### HTML With GZIP Compression Source: https://docs.wp-rocket.me/article/1403-enable-text-compression This example demonstrates how the same HTML file appears after being compressed with GZIP. Note the reduced character count. ```html
...
``` -------------------------------- ### Import WP Rocket Settings from URL Source: https://docs.wp-rocket.me/article/1497-wp-cli-interface-for-wp-rocket Imports WP Rocket settings from a JSON file hosted at a given URL. ```bash wp rocket import --file=https://example.com/wp-rocket-settings.json ``` -------------------------------- ### Example of document.write() usage Source: https://docs.wp-rocket.me/article/1409-avoid-document-write This example demonstrates how document.write() is used to inject a script tag into the page. The browser will block rendering until this script is downloaded and parsed. ```javascript document.write(''); ``` -------------------------------- ### Set up Server Cron Job with PHP CLI Source: https://docs.wp-rocket.me/article/1279-cron-and-wp-rocket An alternative command for setting up a server-side cron job, using the PHP command-line interface. Ensure the path to wp-cron.php is correct for your server environment. ```bash php -q /home/path/public_html/wp-cron.php ``` -------------------------------- ### Example Minified JavaScript File with WP Rocket Source: https://docs.wp-rocket.me/article/46-how-to-check-if-wp-rocket-is-caching-your-pages This is an example of a JavaScript file URL that has been minified by WP Rocket, including the minification path and a version parameter. ```html ``` -------------------------------- ### Safelist CSS Class with Wildcards Example Source: https://docs.wp-rocket.me/article/1718-troubleshoot-remove-unused-css-issues These examples demonstrate using wildcards to safelist CSS classes with variable parts, ensuring broader style inclusion. ```css .my-class(.*) ``` ```css (.*).other-(.*) ```