A plugin file structure helps organize your WordPress plugin files clearly. It makes your plugin easy to understand, maintain, and extend.
0
0
Plugin file structure in Wordpress
Introduction
When creating a new WordPress plugin from scratch.
When adding new features to an existing plugin.
When sharing your plugin with others or publishing it.
When debugging or updating your plugin code.
When collaborating with other developers on a plugin.
Syntax
Wordpress
my-plugin/
├── my-plugin.php
├── readme.txt
├── assets/
│ ├── css/
│ ├── js/
│ └── images/
├── includes/
│ ├── functions.php
│ └── class-my-plugin.php
└── languages/
└── my-plugin.potThe main plugin file (my-plugin.php) is required and contains plugin info and main code.
Folders like assets, includes, and languages help keep files organized by type.
Examples
This is the main plugin file with header info WordPress needs to recognize the plugin.
Wordpress
my-plugin.php
<?php
/*
Plugin Name: My Plugin
Description: A simple example plugin.
Version: 1.0
Author: You
*/
// Plugin main code hereHelper functions can be placed in separate files inside the
includes folder.Wordpress
includes/functions.php
<?php
function my_plugin_helper() {
// Helper function code
}CSS files for styling your plugin’s output go inside the
assets/css folder.Wordpress
assets/css/style.css
/* Plugin styles go here */Sample Program
This simple plugin adds a greeting message at the bottom of every page using the footer hook.
Wordpress
<?php /* Plugin Name: Simple Greeting Description: Shows a greeting message. Version: 1.0 Author: You */ // Hook to add greeting to the footer add_action('wp_footer', function() { echo '<p style="text-align:center;">Hello from Simple Greeting plugin!</p>'; });
OutputSuccess
Important Notes
Always keep the main plugin file in the root plugin folder.
Use folders to separate code, styles, scripts, and translations for clarity.
Follow WordPress coding standards for better compatibility and readability.
Summary
A clear plugin file structure keeps your code organized and easy to manage.
The main plugin file must have plugin header info for WordPress to detect it.
Use folders like includes, assets, and languages to separate different types of files.