In some cases you may need to add a function to your website, either to hook something into the theme, or use a filter to change something in the theme.
When working with PHP, you want to make sure you have access to your server via FTP or File Manager (through your hosting control panel). This is due to how unforgiving PHP is, if there’s an error in the code, your site can turn into a blank white page. To fix this, simply go into your server and delete the code you added.
Code Snippets
The Code Snippets plugin is a very cool way to add PHP snippets to your website. You can activate and deactivate certain snippets, and even adds notes about what they do. I believe it even has better error handling to avoid the PHP error scenario I mentioned above.
To install it, simply go to Plugins > Add New and search for Code Snippets.
Create a Plugin
If you don’t want to use the Code Snippets plugin mentioned above, you can create your own plugin.
Usually, creating a plugin is kind of difficult, but we can actually use a plugin to make creating a plugin easier (still with me?).
First, install Pluginception by going to Plugins > Add New and searching for Pluginception.
Now that it’s activated, go to Plugins > Create New Plugin.
Name it something super specific to you so it doesn’t conflict with any other plugins, and create it.
Now you can add your functions to the plugin file.
Use a Child Theme
If you’re already using a child theme, you can use the functions.php file to add your PHP.