Plugin Headers
Plugin headers are special comments that inform WordPress that this is a plugin and the current file (where the headers are located) is the main file of the plugin from which the plugin starts working.
Such headers look like PHP comments at the beginning of the file. Below we will consider the standard of these headers.
Possible plugin headers
The plugin header must be located in the main file of the plugin and only there.
At a minimum, the header must contain the name of the plugin:
<?php /** * Plugin Name: My First Plugin */ // plugin code
Other data can also be specified in the header:
<?php /** * Plugin Name: Plugin Name * Description: Description of the plugin (140 characters) * * Plugin URI: Link to the plugin page * Author URI: Link to the author * Author: Author's name * * Text Domain: Translation ID, specified in load_plugin_textdomain() * Domain Path: /Path to the translation file * * Requires at least: 5.7 * Requires PHP: 7.0 * * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * * Network: true - activates the plugin for the entire network * Update URI: https://example.com/link_to_update * * Requires Plugins: some-plugin, some-plugin-2 * * Version: 1.0 */ // plugin code
- Plugin Name:(required)
- The name of the plugin that appears in the plugin list in the admin panel.
- Description:
- A brief description of the plugin that appears in the Plugins section in the admin panel. It is recommended not to exceed 140 characters.
- Version:
- The current version number of the plugin, for example, 1.0 or 1.0.3.
When installing a version, keep in mind that WP uses the function version_compare() to compare versions. Therefore, when changing the version, make sure that the new version is higher. For example, 1.02 is greater than 1.1.
- Plugin URI:
- The homepage of the plugin, which can be on WordPress.org or on your own site.
- The name of the plugin author. There may be more than one author in the list.
- The author's website or profile on another website, such as WordPress.org.
- Requires at least:
- The minimum required version of WordPress. For example: 5.7.
- Requires PHP:
- The minimum required version of PHP. For example: 7.4.
- License:
- The short name of the plugin's license, such as GPL2. More detailed information about licensing can be found on WordPress.org.
- License URI:
- A link to the license, for example, https://www.gnu.org/licenses/gpl-2.0.html.
- Text Domain:
The translation identifier (localization domain), used in localization functions and in the name of the translation file
.moor.l10n.php.For more details, see the quote here.
- Domain Path:
Indicates the path to the folder where translation files should be searched.
Usually, this is specified as
/languagesand there is alanguagesfolder in the plugin containing.moor.l10n.phptranslation files.The value must start with a slash
/. If there is no slash, an error may occur. Noted on WP 6.8 when the translation file is loaded automatically (the code does not use load_plugin_textdomain())- Network:
- Specify "true" to ensure the plugin is activated across the entire network of sites in MU WordPress build. This will make it impossible to activate the plugin for a single site if the multisite is activated.
- Update URI:
- The URL for the update site. Used in the function wp_update_plugins(). A hook update_plugins_(hostname) will be created from the domain.
- Requires Plugins:(WP 6.5)
A list of plugins that the current plugin depends on. You need to specify the plugin slugs (comma-separated). For example,
my-plugin(usually this is the name of the plugin folder).The format
my-plugin/my-plugin.phpis not supported.Read more about plugin dependencies here.
Header size
The plugin header is parsed by the function get_plugin_data(), which processes only the first 8KiB (6000-8000 characters) of information, and if the plugin data exceeds this, the author will have to reduce it or move the plugin data to the top. This can happen, for example, if license data is added before the plugin data.
Specifying the plugin license
Most WordPress plugins are published under the GPL license, which corresponds to the same license that WordPress itself uses. However, there are other options. It is always better to clearly specify which license your plugin uses.
It was shown above that the license can be specified in the header parameter License:. But there is another common practice - to place a license block under the plugin headers in the main plugin file.
The license block looks something like this:
{Plugin Name} is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
{Plugin Name} is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with {Plugin Name}. If not, see {URI to Plugin License}.
Combined with the plugin headers, we get:
/**
* Plugin Name: Plugin Name
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: This describes my plugin in a short sentence
* Version: 1.5
* Author: John Smith
* Author URI: http://URI_Of_The_Plugin_Author
* License: GPL2
*
* {Plugin Name} is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* {Plugin Name} is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with {Plugin Name}. If not, see {License URI}.
*/
PHPDoc DocBlock
You can also mix anything into the headers, for example, you can add a PHPDoc documentation block for various IDEs:
/** * Plugin Name * * @package PluginPackage * @author Your Name * @copyright 2019 Your Name or Company Name * @license GPL-2.0-or-later * * @wordpress-plugin * Plugin Name: Plugin Name * Plugin URI: https://example.com/plugin-name * Description: Description of the plugin. * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Your Name * Author URI: https://example.com * Text Domain: plugin-slug * License: GPL v2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */
--
Also read: https://developer.wordpress.org/plugins/plugin-basics/header-requirements/