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 My Custom Functions.
- Go to Settings > PHP Inserter.
Add the code, change the status to On, and click on Save changes. Example:
Clear WP Rocket's cache.
You can also use this other plugin: https://wordpress.org/plugins/code-snippets/.
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.