We think this file is a misnamed, but it is the standard name of this file that WordPress looks for. The header.php file includes everything at the top of your rendered page, up to the content area. The reason we think this is confusing is because a properly formatted HTML document includes its own <head> information, which has its own special requirements. This header.php template file includes the HTML head, but it also includes the start of the HTML document and usually includes the site logo and navigation, assuming you are using an across-the-top horizontal navigation scheme. It can also include any additional elements at the top of your page, such as secondary navigation or a search area.
Because this file includes so much more than the HTML header, we tend to take the printing term and call this area the nameplate, as in the nameplate of a newspaper or magazine. However, we do stick with tradition and leave the filename header.php in order to remain compatible with the built-in functionality of WordPress.
When creating your header template file there is a very important WordPress function that must be included: wp_head (). This is a hook for WordPress to queue in certain functionality into your site and is used by plugins. For some reason this function is not included in early Sandbox templates, so check that it is included.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
11 http: //www.w3 . org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php wp_title( '-', true, 'right' ); echo wp_specialchars( get_bloginfo('name'), 1 ) ?> </title>
<meta http-equiv="content-type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url') ? >" />
The wp_head () function is dropped in your HTML <head> node and is critical to the long-term compatibility and functionality of your theme.
Now that you have broken out the nameplate section of your pages into the separate header. php template, you need to adjust your index. php file to include it. You could use the traditional PHP include or require family of functions, but the WordPress core functionality has a handy function to get around the theme paths. At the top of your index.php (and subsequent template files discussed later) simply add the following code:
This function automatically includes the filename header.php from the current theme's directory into the current file for rendering. This function does not have any additional functionality over a PHP include besides determining the correct include path for you, but we find it much more readable when working on a theme.
Optionally, you could split out additional components from your header.php file and include them back in with PHP includes. Occasionally, if a site has a particularly long or complex global navigation, we break it out for inclusion. In practice, working on smaller files is easier for editing, because each template file has a specific function and reduces the complexity of debugging.
In the same vein as the header.php file, everything below your content area should be separated out into a footer file. The nature of footer files has changed recently. Historically they have been the copyright and contact information but in recent years, this real estate has been expanded to include additional navigation options and information relevant to your site. What you put in your footer is up to you, but because it remains by and large the same on every page, it is a prime candidate for breaking out into a separate include.
Again, make sure you incorporate the wp_foot () function into your footer template. This function allows WordPress to inject any necessary information from your active plugins and, as a rule, will include your </body></html> closing tags.
Similar to the way your header template is included, WordPress offers the same functionality for your footer information. At the bottom of your template files add the following code:
Another candidate for breaking out is the sidebar, which is everything to the right or left of your content. This could be the navigation of your site, if you have elected a vertical navigation scheme, as well as the less important, or supporting information on your site.
Was this article helpful?