WordPress: Include Template Tags

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

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.

This code block will look for a template file named header-contact.php

Footer Include tag

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.

This code block will look for a template file name footer-home.php

Sidebar Include tag

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.

This code block will look for a template file name sidebar-blog.php



Custom Include tag

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.

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.

For example, above code block will include a file named loop-index.php.

Search form Include tag

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

Comment include tag includes comments.php template file from current theme directory.

Related posts

Leave a Comment