Paulund
2012-06-25 #wordpress

WordPress File Header Comments

The best thing about Wordpress is that everything it does is extensible, this means that developers can do anything they want by building on top of the Wordpress framework. When creating files that need to be used by Wordpress they are defined into 3 areas, they are either Wordpress themes, Wordpress plugins or Page templates. Each one of these types of files need to be defined to Wordpress so that it understands how to use them. To help Wordpress understand how to use them you need to provide it with a number of different parameters in comments at the top of the main file.

Wordpress Plugin Header Comments

When you create a new Wordpress plugin you need to define the plugin by using file header comments. These comments should be placed in the main PHP file for the plugin. This will be the first file that will run when the plugin is activated. This is where you will place the action or filters to perform your functionality. When you add these comments to the PHP file Wordpress understands that this is a plugin and will add it to the plugin dashboard area and will allow the user to activate the plugin. If the plugin does not have the header information then the user will not be able to activate the plugin and the code will never run. Here is the default information that is required by Wordpress for a plugin:

  • Plugin Name
  • Plugin URL
  • Plugin Description
  • Version number
  • Author Name
  • Author URL
  • License Information

Therefore the comments will look something like this.

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>

The information within the comment will be used to display a description to the user on the plugin dashboard.

Wordpress Theme Header Comments

When you develop a new Wordpress theme you need to do the samething as the plugin and use a block of comments to define these files as a Wordpress theme. Also these comments are going to be used as a description in the theme selector screen. The difference with Theme development is that you need to place these comments at the top of the theme stylesheet. The information is similar but it is going to help your theme be found when searched for. Two themes are not allowed the same information the Theme comments block, if you create your theme by copying an existing theme then you will need to change these comments before you can use the theme. Here is the information that is expected from the Theme file headers. - Theme Name

  • Theme URL
  • Theme Description
  • Author
  • Author URL
  • Version Number
  • Search Tags
  • License Information

Here is what the file header comments will look like.

/*
Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 default theme for WordPress.
Author: wordpressdotorg
Author URI: http://wordpress.org/
Version: 1.0
Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style, custom-menu (optional)

License:
License URI:

General comments (optional).
*/

Page Templates Header Comments

The third developer file header comments that are needed in your Wordpress site are Page template file headers. If you want to create new page templates then you will need to add this comment to the top of the file. These comments are very simply all you need is the Page template name and the description for the page.

<?php
/*
* Template Name: Custom Page Template
* Description: Description of the page template
*/
?>