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.
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 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 */ ?>
Learn how to code with Treehouse
- Learn projects with access to 1000+ videos
- Practice live with our Code Challenge Engine
- Get help in our members-only forums
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.
Subscribe today and get a 50% discount code to Paulund