You can add pieces of PHP code snippets into your theme’s functions.php file. This is a common place to store custom code.
If you are unable to edit the file or do not want to touch your theme code you can use a plugin such as WPCode – Insert headers and footers – Free from WordPress.org.
This is a great little tool to add custom code to your website without editing any files in your theme or plugins.
- Log in to your website and go to “Plugins” -> “Add New”
- Search for “my custom functions” and locate the plugin named “My Custom Functions by Space X-Chimp.
- Install the plugin using the button “Install Now” and then wait a few seconds until you can click “Activate”.
- After the plugin is activated, go to “Settings” -> “PHP Inserter”.
- Here, you can copy-paste the code above.
- Make sure to customise to filter out the files and folders you want to whitelist using the examples above.