How does the WordPress plugin file structure typically work, including the required plugin header comment that WordPress uses to recognize and display a plugin?
Short answer
A WordPress plugin at its simplest consists of at least one PHP file placed within its own dedicated folder inside the wp content plugins directory, and that main PHP file must begin with a specially formatted comment block, known as the plugin header, containing metadata such…
Advertisement
AModel answer
A WordPress plugin at its simplest consists of at least one PHP file placed within its own dedicated folder inside the wp content plugins directory, and that main PHP file must begin with a specially formatted comment block, known as the plugin header, containing metadata such as the plugin's name, version number, and description, which WordPress specifically reads and uses to correctly display that plugin within the admin dashboard's plugins list, allowing a site administrator to then activate or deactivate it.
<?php
/**
* Plugin Name: Simple Contact Form
* Description: Adds a basic contact form shortcode.
* Version: 1.2
* Author: Your Name
*/
if (!defined('ABSPATH')) exit;Real-world example
A developer creates a new plugin folder containing a single main PHP file with a properly formatted plugin header comment, allowing WordPress to correctly recognize, list, and allow activation of that new plugin directly from the admin dashboard.
Likely follow-ups
- Why is checking for the ABSPATH constant considered an important security practice in a plugin's main file?
- How does a plugin properly organize its code across multiple files as it grows larger?
Related topics