| CARVIEW |
Include Tags
Languages: English • 日本語 Português do Brasil • Македонски • (Add your language)
Contents
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
|
|
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
- 1.5 :
-
get_header()was added to include the template header. -
get_footer()was added to include the template footer. -
get_sidebar()was added to include the template sidebar.
-
- 2.5 :
- The name parameter was added to
get_sidebar().
- The name parameter was added to
- 2.7 :
- The name parameter was added to
get_header(). - The name parameter was added to
get_footer(). -
get_search_form()was added to include the search form.
- The name parameter was added to
- 3.0 :
-
get_template_part()was added to include the template other generic files.
-
Source File
- Browse source:
wp-includes/general-template.php
Related
Include Tags
- Function: get_header(),
- Function: get_footer(),
- Function: get_sidebar(),
- Function: get_template_part(),
- Function: get_search_form(),
- Function: comments_template()