Adding PHP Code

Occasionally, normally due to ‘filters’, you will need to add some snippets of custom PHP to get the desired results. Conventional wisdom would have you create a Child Theme and add the snippets to the functions.php, but that is overly complex a solution unless you are into serious theme customisation.
I will cover two alternatives way, one my recommended method, the other for those that find even editing files on the server a challenge.

Create a custom code plugin

It might sound daunting writing a plugin but it is not. Find your wp-content/plugins directory and create a subfolder with any name you fancy, e.g. wp-content/plugins/my-custom-code and in that folder create a file called index.php and add the following code:

Add your custom code to the file, save and then go to plugins and activate.

Use a Code Snippet Plugin

An alternative to editing a file is to use a Code Snippet Plugin.

There are several Code Snippet plugins available that make adding PHP code simple. None of these plugins are mine, so this is just information, but I can’t support them or even assure you they will work properly. Any issue you should take up with the plugin developers, here are a fewI found, others are available :-

Was this helpful?