Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Include Tags

Include Tags

The Template include tags are used within one Template file (for example index.php) to execute the HTML and PHP found in another template file (for example header.php). PHP has a built in include() statement for this purpose, but these WordPress template tags make including certain specific files much easier.

See Using Themes and Theme Development for more information about Templates and Themes.

Function Reference

Include Generic Files
Include Other Components


The Header Template

<?php get_header(); ?>

The get_header() tag includes the file header.php or header-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/header.php.

The Footer Template

<?php get_footer(); ?>

The get_footer() tag includes the file footer.php or footer-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/footer.php.

The Sidebar Template

<?php get_sidebar(); ?>

The get_sidebar() tag includes the file sidebar.php or sidebar-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/sidebar.php.

Custom Template files

<?php get_template_part(); ?>

The get_template_part() tag includes the file {slug}.php or {slug}-{name}.php from your current theme's directory, a custom Include Tags other than header, sidebar, footer.

The Search Form Template

<?php get_search_form(); ?>

The get_search_form() tag includes the file searchform.php from your current theme's directory. If that file is not found, it will generate the search form.

See also get_search_form and Migrating Plugins and Themes to 2.7 for more detail.

The Comments Template

<?php comments_template(); ?>

This tag includes the file comments.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/comments.php. To display comments on the main index or archive pages, you'll need to set the $withcomments variable to "1" before calling this tag.

Example

The following is a very simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).

<?php get_header(); ?>
<?php get_template_part('nav'); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Parameters

get_header(), get_footer() and get_sidebar() accepts one parameter:

$name
(string) (optional) Calls for sidebar-{name}.php. For Example: sidebar-right.php, header-single.php or footer-8.php.
Default: None

get_template_part() accepts two parameters:

$slug
(string) (required) Calls for {slug}.php. For Example: nav.php
Default: None
$name
(string) (optional) Calls for {slug}-{name}.php. For Example: nav-home.php
Default: None

Changelog

Source File

Related

Include Tags

See also index of Function Reference and index of Template Tags.