WordPress include Template Tags work same way as PHP include(). These tags include other template files and execute their HTML or PHP code.
Template Tags can pass parameters and it enable us to use multiple template tags for different purposes.
Let’s look at these Template tags:
Header Include tag
0
1
2
|
<?php get_header(); ?>
|
Header include tag get_header()
. includes header.php
from current theme. If you are using it in Child theme, it includes child theme header.php if available. Otherwise parent theme header.php is included.
Header include tag can also have name parameter. In that case a header file like header-{name}.php
will be included.
0
1
2
|
<?php get_header( ‘contact’ ); ?>
|
This code block will look for a template file named header-contact.php
Footer Include tag
0
1
2
|
<?php get_footer(); ?>
|
Same as header include tag Footer include tag includes footer.php
from current theme. It can also have a name parameter. If name parameter is used then it include a footer-{name}.php
template file.
0
1
2
|
<?php get_footer( ‘home’ ); ?>
|
This code block will look for a template file name footer-home.php
Sidebar Include tag
0
1
2
|
<?php get_sidebar(); ?>
|
Same as header include tag Sidebar include tag includes sidebar.php
from current theme. It can also have a name parameter. If name parameter is used then it include a sidebar-{name}.php
template file.
0
1
2
|
<?php get_sidebar( ‘blog’ ); ?>
|
This code block will look for a template file name sidebar-blog.php
Custom Include tag
0
1
2
|
<?php get_template_part(); ?>
|
Unlike header, footer and sidebar include tag, it is custom include tag which include any custom file {slug}.php
where slug pass as parameter. It will not work without a slug parameter.
0
1
2
|
<?php get_template_part(‘loop’); ?>
|
This code block will include a file named loop.php
Custom include tag also have name parameter. If name parameter is used then it include a file {slug}-{name}.php.
0
1
2
|
<?php get_template_part( ‘loop’, ‘index’ ); ?>
|
For example, above code block will include a file named loop-index.php
.
Search form Include tag
0
1
2
|
<?php get_search_form(); ?>
|
Search form Include tag includes searchform.php template file from current theme directory. If searchform.php don’t exits then it generated it.
Comment Include tag
0
1
2
|
<?php comments_template(); ?>
|
Comment include tag includes comments.php
template file from current theme directory.