This entry is part 2 of 14 in the Plugin Development 101 Series
- Introduction to WordPress Plugin Development 101
- Plugin Development 101 – What Makes a Plugin?
- Plugin Development 101 – General Best Practices
- Plugin Development 101 – An Intro to Filters
- Plugin Development 101 – Intro to Actions
- Plugin Development 101 – Registering a Custom Post Type
- Plugin Development 101 – Intro to Short Codes
- Plugin Development 101 – Intro to Loading Scripts and Styles
- Plugin Development 101 – Introduction to Adding Dashboard Menus
- Plugin Development 101 – Separating Your Plugin into Multiple Files
- Plugin Development 101 – Your First OOP Plugin
- Plugin Development 101 – Dissecting the Featured Comments Plugin
- Plugin Development 101 – Digging Into WordPress Core to Solve a Problem
- Plugin Development 101 – Introduction to extending classes
In this first real part of the Plugin Development 101 tutorial series we look into what makes a plugin. How is a plugin different than any other .php file? How do you make WordPress recognize your code as a plugin?
A plugin in WordPress is really nothing more than a PHP file (or multiple PHP files) with a very specific piece of information included at the top of the file that has been placed in the wp-content/plugins/ folder.
There is no minimum or maximum for what a plugin can or must do. Plugins can be a single line of code, or 50,000 lines of code. Regardless of the size of a plugin, it is defined as a plugin in exactly the same way: by a piece of meta data placed in the main file.
At the top of every WordPress plugin is a comment block that contains information about the plugin:
- The name of the plugin
- A brief description of the plugin
- The URL of the plugin’s homepage
- The author of the plugin
- The author’s website
- The plugin version number
The meta data is always placed in a comment block, so like:
1 2 3 4 5 6 7 8 9
<?php /* Plugin Name: Featured Comments Plugin URI: https://pippinsplugins.com/featured-comments Description: Lets the admin add "featured" or "buried" css class to selected comments. Handy to highlight comments that add value to your post. Also includes a Featured Comments widget Version: 1.2.1 Author: Pippin Williamson Author URI: https://pippinsplugins.com */
All but the Plugin name lines are optional. A plugin can be defined with just this:
1 2 3 4
<?php /* Plugin Name: Featured Comments */
This comment block should only ever be placed in the main plugin file, if your plugin has more than one.
The simple presence of this code block is all that is needed for WordPress to recognize your code as a plugin.
We will go into how to organize your plugin code in one of the upcoming parts of this series, for now just remember that a plugin is nothing more than a .php file placed inside of wp-content/plugins that contains the comment block shown above.