Creating a WordPress Plugin file for your extra code

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:

  1. Navigate to your plugins directory
  2. Create a new directory (name of the directory is optional, for example “”)
  3. Create a PHP file in that directory (name of the file is also optional, be creative)
  4. Open that PHP file and paste the following code into it:
  6. 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 plugin file or whatever you have named your file.

Start Blog Book


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *