Once you start customizing your newly created WordPress website, you’ll find yourself adding a new theme, plugins and extra code to the theme files. A line of code here, few lines of code there and you’ll create a mess.
Not only this will look terrible but you will give yourself a hard time finding your custom code once you need it. Not to mention the problem you are creating for someone new trying to work on your site.
On the Internet as well as on our site, you will often find those pieces of code (snippets) which you need to copy and paste into your theme’s functions.php file. If you have to add just one extra function to your theme, this is completely ok. But if you find yourself adding more than just a few functions, you should consider creating a site-specific plugin.
By creating this file, you’re basically creating a simple plugin which your theme can recognize and work with. This means all your custom code is stored into one file which is not messed with the original functions.php. First of all, if you’re not using child theme and you need to update your theme’s files, you won’t be losing the extra added code you have created. Second, if you write the code from the WordPress built-in editor and the code doesn’t work, you won’t be facing the “white screen of death” which you have probably encountered more often than not.
Let’s create a file and write code into it:
- Navigate to your plugins directory
- Create a new directory (name of the directory is optional, for example “firstsiteguide.com”)
- Create a PHP file in that directory (name of the file is also optional, be creative)
- Open that PHP file and paste the following code into it:
- Activate your newly created plugin in WordPress
That's it! Now if you want to add a new piece of code to your theme, use this file. For example, if you want to limit the length of your comments, follow the instructions we have given you but instead of pasting the code into functions.php, use the newly created isitwp.com plugin file or whatever you have named your file.
- Allow users to register and login to your WordPress site using e-mail
- How to enable Output Compression in WordPress using PHP
- Don't let visitors see a broken site while you're doing maintenance
- How to change maximum media file size in WordPress
- How to run PHP code directly from WordPress posts and pages