Add PHP Code Without Editing Files

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.

  1. Go to Plugins → Add New and install and activate the plugin. This will add a Snippets item to your wp-admin dashboard menu.
  2. Navigate to Snippets → Add New.
  3. Enter a title.
  4. Paste or type your code in the Code field.
  5. Click Save Changes and Activate.

Important Notes

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“.

Was this helpful to you?