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 My Custom Functions.
  2. Go to Settings > PHP Inserter.
  3. Add the code, change the status to On, and click on Save changes. Example:

  4. Clear WP Rocket's cache.

You can also use this other plugin:

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.