The best way to apply changes to your WordPress site is to add them in parts/snippets without touching any files in a plugin or the theme your using.
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.
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, search Code Snippets 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”.

Install via WP-CLI command.
wp plugin install code-snippets --activate
If you have set a priority on the filter/hook. It is best that you set the priority at the same level. You also want to set/leave it on “Run snippet everywhere”.