How to Structure a WordPress Plugin’s Files

If you purchase through a link on our site, we may earn a commission. Learn more.

An important aspect of keeping your plugin well organised is to create a file and folder structure that makes sense. I've recently done some research on how the leading plugin developers are structuring their plugins, and would like to share this with you.
Table of Contents
WP Engine High Performance Hosting
BionicWP Hosting

An important aspect of keeping your plugin well organised is to create a file and folder structure that makes sense.

I’ve recently done some research on how the leading plugin developers are structuring their plugins, and would like to share this with you.

It seems that most developer favour a Model View Controller (MVC) structure for complex plugins, but I haven’t really developed such complex plugins yet, so I’m not going to go into that. Just for reference, follow this link to see how an MVC structure typically looks like.

This is the structure I tend to use most when developing plugins:

[php]
my-plugin/
inc/
Any additional plugin-specific PHP files go here
lib/
Library classes, css, js, and other files that I use with many
plugins go here
css/
js/
images/
lang/
Translation files
my-plugin.php
readme.txt
[/php]

If you prefer to have your root directory a bit cleaner, you can use the WordPress Core practice of putting the /js, /css and /images folders in the /inc folder as well.

Here’s another nice structure you can use:

[php]
my-plugin/
admin/
holds all back-end administrative files
js/
holds all back-end JavaScript files
css/
holds all back-end CSS files
images/
holds all back-end images
admin_file_1.php back-end functionality file
admin_file_2.php another back-end functionality file
js/
holds all front end JavaScript files
css/
holds all fronted CSS files
inc/
holds all helper classes
lang/
holds all translation files
images/
holds all fronted images
my-plugin.php main plugin file with plugin meta, mostly includes,action and filter hooks
readme.txt
changelog.txt
license.txt
[/php]

Lets take a look at the structures used by some popular plugins, starting with Easy Digital Downloads:

[php]
my-plugin/
assets/
assets/
css/
images/
js/
includes/
admin/
libraries/
languages/
templates/
my-plugin.php
license.txt
readme.txt
uninstall.php
[/php]

Of course, each developer will have his own preferences and that’s not necessarily a bad thing. For new developers and those seeking guidance on how to structure their files, I recommend the above format. You can build your own template and use it as a start for every new plugin you create.

If you want a ready made boilerplate, check out Tom McFarlin’s WordPress Plugin Boilerplate on GitHub. Here are some of its features:

  • The Plugin Boilerplate is fully-based on the WordPress Plugin API
  • Uses PHPDoc conventions for easily following the code
  • Liberal use of TODO to guide you through what you need to change
  • Uses a strict file organization scheme to make sure the assets are easily maintainable

If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.

Jean Galea

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Discover more from our archives ↓

Popular articles ↓

4 Responses

  1. Thanks.. I need some code for any plugin with explanation how to create a plugin.. Because i am new to wordpress.. now i need to create a plugin in wordpress.. Can anyone help me with clear explanation of plugin files..

  2. That’s pretty much the same structure I use. I do sometimes have a ‘templates’ directory and ‘admin’ if I have several admin files, other than that it’s the same.

Share Your Thoughts

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

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.