iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Plugin Header

WordPress plugin header: the magic block at the top of the main PHP file that registers a plugin with the WP installer.

WordPress — plugin header

EXAMPLE
<?php
/**
 * Plugin Name:       My Cool Plugin
 * Plugin URI:        https://example.com/my-plugin
 * Description:       A plugin that does cool things.
 * Version:           1.0.0
 * Requires at least: 6.0
 * Requires PHP:      8.1
 * Author:            Your Name
 * Author URI:        https://example.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       my-plugin
 * Domain Path:       /languages
 * Network:           false
 * Update URI:        https://example.com/my-plugin/updates
 */

// Prevent direct access:
if (!defined('ABSPATH')) { exit; }

// Plugin code starts here...

// ===== Required fields =====
// Plugin Name is the ONLY required field. The rest are strongly recommended.

// ===== Common patterns =====
define('MY_PLUGIN_VERSION', '1.0.0');
define('MY_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('MY_PLUGIN_URL', plugin_dir_url(__FILE__));

require_once MY_PLUGIN_DIR . 'includes/init.php';

// ===== Activation / deactivation hooks =====
register_activation_hook(__FILE__, function () {
    // create tables, add options, etc
    add_option('my_plugin_version', MY_PLUGIN_VERSION);
});

register_deactivation_hook(__FILE__, function () {
    // cleanup that should run when deactivated (NOT on every update)
});

register_uninstall_hook(__FILE__, 'my_plugin_uninstall');
function my_plugin_uninstall() {
    delete_option('my_plugin_version');
    // remove tables if appropriate
}

// ===== File / folder layout (recommended) =====
// my-plugin/
//   my-plugin.php       (the main file with the header above)
//   includes/
//     init.php
//     class-admin.php
//     class-rest.php
//   assets/
//     js/
//     css/
//   languages/
//     my-plugin.pot
//   readme.txt
//   uninstall.php       (alternative to register_uninstall_hook)

// ===== Multisite =====
// Network: true -> network activate; per-site activation blocked
// Network: false (default) -> per-site activation

// ===== Update URI =====
// For hosting your own updates (outside wordpress.org):
// Update URI: false                -> opt out of any update checking
// Update URI: my-plugin             -> ignored by wordpress.org (use slug not on .org)
// Update URI: https://example.com/  -> hit your own update server

// ===== readme.txt =====
// Standard WP plugin readme:
=== My Cool Plugin ===
Contributors: yourname
Tags: cool, fun, useful
Requires at least: 6.0
Tested up to: 6.5
Stable tag: 1.0.0
License: GPLv2 or later

== Description ==
A plugin that does cool things.

== Changelog ==
= 1.0.0 =
* Initial release

// ===== Patterns to internalise =====
// - Header in the MAIN plugin file (named after the slug)
// - Constants for version + paths at the top
// - Activation / deactivation / uninstall lifecycle hooks
// - readme.txt for wordpress.org listings (even if not submitting)

// ===== Pitfalls =====
// - Activation hook code that runs on every page load (it doesn't - misunderstanding)
// - Missing 'Requires at least' / 'Requires PHP' -> users on old versions see fatal errors
// - Plugin Name with HTML / quotes -> rendering bugs in admin
// - Updating without bumping Version -> caches stick on old version

Why it matters

The plugin header is the contract between your code and WordPress. Plugin Name + Version + the requires-at-least fields prevent half the support tickets. Pair with activation / deactivation / uninstall hooks for a clean lifecycle, and a readme.txt for distribution polish.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
<?php
/**
 * Plugin Name: My Plugin
 * Version: 1.0.0
 * Author: You
 */
Try it Yourself »

Discussion

Loading…