Lately, we have been modifying a lot of WordPress themes for client and internal projects. Along the way, we inevitably want to add a few lines of code to the active theme’s function.php file. In this tutorial we are adding a code snippet to a Genesis Child Theme, but the same practice can be applied to any WordPress theme. The only difference is the code snippets used. StudioPress provides a long list of tutorials and code snippets for modifying your Genesis child theme.
Using the built in Theme Editor in WordPress Admin is not the best way to modify theme files, and incorrectly entering code into your function.php file can crash your site. Resulting in the infamous WordPress “white screen of death”. Not good.
One of the best ways to modify your theme’s function.php file without risking the integrity of your site is with a functionality or “site” plugin. This is a simple plugin shell that you create to add code snippets or additional functionality to your website, without modifying your theme files. Huge thanks to a previous WPBeginner article, What, Why, and How-To’s of Creating a Site-Specific WordPress Plugin, for the inspiration for this post.
How to Create a Site Plugin to Modify your Theme’s Function.php File
In this tutorial, we will show you how to quickly create a functionality plugin (or site plugin) for your WordPress theme. We will refer to this plugin in future tutorials that require modification to the theme’s function.php file.
You can download the final plugin file that we created in this tutorial from our WordPress Toolbox. It’s free to access, just subscribe to our list to gain access to our toolbox of freebies.
Step 1. Create a Text file using a Text Editor
Using a Mac, you can create a clean Text file using the standard TextEdit app (Use the similar NotePad editing program in Windows).
Step 2. Add the following code to setup create a plugin
Step 3. Add any Code Snippets
Here’s an example Code Snippet for adding an “Updated on” date in the Post Info section:
Step 4. Save your file with .php extension
Step 5. Add your .php file to a new folder and compress
Step 6. Upload and activate your new plugin
Update or Modify your Site Plugin
The best practice is to use FTP to update or modify your plugin files. That way you can quickly correct any mistakes or errors and still access your WordPress Admin area.
If you are not familiar with FTP or want to be able to modify your plugin file using the Theme Editor, first deactivate your Site Plugin. Then make your changes and Activate the plugin. WordPress will not activate the plugin if there are errors in the file. Instead, you will receive a warning message at the top of your WordPress Admin area. You can use this error message to fix your Site Plugin files and then try to Activate. Please note that this is not the recommended way to update your plugin files, but following these steps will help protect your site from crashing due to an error in your plugin file.
Bonus Content – Instant Download
Download the complete plugin template from our WordPress Toolbox to get started quickly.