Add code snippets

In some cases, you might need to use snippets to fix specific issues or change WP Rocket's default behavior.

There are two ways to achieve this:

Add the snippet using a plugin

For many WordPress users, using a plugin to add the snippet is the easiest way. Here are the steps:

  1. Install a free plugin called Code Snippets.
  2. Go to Snippets > Add New > Functions tab.
  3. Enter a title for your custom code, add the code, save the changes, and click to activate your code snippet. Example:

  4. Clear WP Rocket's cache.

You can also use this alternative plugin: https://wordpress.org/plugins/insert-headers-and-footers/

Add snippets via functions.php file

You can also add the code in the functions.php file in your child theme, like this: 

  1. Go to the /wp-content/themes/your-child-theme/ folder.
  2. Edit the functions.php file.
  3. Add the code to the bottom of the file:

  4. Clear WP Rocket's cache.

This approach requires proper (s)FTP access and a bit of experience in editing WordPress files.

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