The best way to apply changes to your store is to add them in parts/snippets without touching any files in a plugin or the theme your using.
This quick guide explains how to use a functionality plugin instead.
Editing other PHP file carries the risk of breaking the rest of the code in the file and also opens you to the potential that the code will be lost when you update.
Instead, you can safely add code snippets using a plugin.
There are several functionality plugins available in the WordPress.org repository. The instructions below explain how to install and use a plugin called Code Snippets.
- Go to Plugins → Add New and install and activate the plugin. This will add a Snippets item to your
- Navigate to Snippets → Add New.
- Enter a title.
- Paste or type your code in the Code field.
- Click Save Changes and Activate.
If you have set a priority on the filter/hook like the example above. It is best that you set the Priority at the same level. You also want to set/leave it on “Run snippet everywhere“.