Understanding Plugin Structure

All that is required for WordPress to see a plugin is a PHP file in the wp-content/plugins directory of the site with some special information at the top of the file. This information at the top of a plugin file, typically referred to as a plugins header, is what WordPress looks for when determining which plugins are installed on the site. A freshly installed WordPress site makes a good starting point to understand how this works in practice.

Inspecting WordPress's default plugins

WordPress installs with two plugins by default: Akismet and Hello Dolly. Looking at the files for each of these plugins will help you understand how you can structure your own plugins.

Inside a fresh WordPress site's wp-content/plugins directory, you find a directory named /akismet and two files named hello.php and index.php. The hello.php file is for the Hello Dolly plugin and has the following text at the top of the file.

<?php
/**
 * @package Hello_Dolly
 * @version 1.5.1
 */
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/#
Description: This is not just a plugin, it symbolizes the hope and
    enthusiasm of an entire generation summed up in two words sung most
    famously by Louis Armstrong: Hello, Dolly. When activated you will
    randomly see a lyric from <cite>Hello, Dolly</cite> in the upper
    right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.5.1
Author URI: http://ma.tt/
*/

The section in bold is the plugin header, which tells WordPress ...

Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.