Friday , 17 November 2017
Home / Programming / WordPress / Plugins / WordPress Plugin Structure – WordPress Plugin Tutorial
WordPress Plugin Structure
WordPress Plugin Structure

WordPress Plugin Structure – WordPress Plugin Tutorial

This post is part of the WordPress Plugin tutorial series. To find a link to all tutorials in order, then please click here.

Let’s take a look at WordPress plugin structure. Let me make this clear, this is by no means the official way to structure your plugin. In fact, if you took a look at how other plugins are structured, then you’ll find it’s organized a completely different way than what I’m showing. Some plugin developers are lazy and put all their files in 1 folder. This makes it hard to navigate and find what you’re looking for. Other developers create a very thorough and well structured plugin.

We’re going to be working with our template plugin. The point of this plugin is to have a basic template ready to copy and paste when we want to create a new plugin. It saves you time and makes life a whole lot easier.

WordPress Plugin Structure

We’ll have 5 folders in total in our template folder. Create the following folders:

  • css –  This will hold all your CSS files.
  • img – This will hold all your images.
  • inc – This will hold all PHP files that are included in your main plugin file.
  • libs – This will hold any libraries you’re using for your project. There will be times where you’ll be using someone else’s library and this will be the place where you’ll want to place all their files inside of.
  • js – This will hold all your JavaScript files.

There will be times where you won’t be using any of the folders at all. This can be for any reason. If you happen to not be using a folder, it’s OK to delete it. You’ll be in situations where you’ll want to create extra folders. For example, if you’re creating a very complex admin panel for your users, then it’s probably best to create a folder called admin. You want your WordPress plugin structure to be flexible and easy to navigate.

Important Files

There are also some files which you should store in the root directory of your plugin such as CHANGELOG.txt, LICENSE.txt, and README.txt. You don’t NEED to have these files, but it’ll be very useful for anyone who downloads your plugin and would like a little more information about your WordPress plugin.

Lastly, another file you can have is uninstall.php. We haven’t created an actual plugin yet and we haven’t talked about what should be done when a plugin is installed. For future reference, WordPress searches for an uninstall.php in the root directory of your plugin when someone decides to uninstall your plugin. These files are great to have in your WordPress plugin structure.

We’ll be talking more about how to uninstall a plugin in a later lesson. In total, this makes 5 files in our root directory of our plugin. I’ll let you decide as to whether or not you should add more files, but for this series, we’re going to keep everything organized and the only files we’ll have in our root directory is our main index.php file and our uninstall.php file. Feel free to comment and tlell me about your own WordPress plugin structure.

Here’s what our current wpTemplate plugin looks like.

WordPress Plugin Structure
WordPress Plugin Structure

Here’s link to a great article on file organization in general.

http://www.microsoft.com/atwork/productivity/files.aspx#fbid=LFA3ycIHuLH

About Jasko Koyn

Check Also

WordPress Meta Boxes

WordPress Meta Boxes – WordPress Plugin Tutorial

WordPress meta boxes are used to display certain information or options in a page. It’s …

Leave a Reply

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

ULTIMATE WORDPRESS DEVELOPMENT COURSE
Want to learn how to create your own custom WordPress plugins and themes? Check out my course!
Get 93% off my course. You'll also learn how to integrate WooCommerce and BuddyPress into your projects. This is a limited time offer
Yes, I would like to get 93% off your course!
No Thanks!
close-link