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:
- Install a free plugin called Code Snippets.
- Go to Snippets > Add New > Functions tab.
-
Enter a title for your custom code, add the code, save the changes, and click to activate your code snippet. Example:
-
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:
- Go to the /wp-content/themes/your-child-theme/ folder.
- Edit the functions.php file.
- Add the code to the bottom of the file:
- Clear WP Rocket's cache.
This approach requires proper (s)FTP access and a bit of experience in editing WordPress files.