1. Home
  2. Docs
  3. WordPress Developer
  4. WordPress Theme Development
  5. Template partials

Template partials

A template partial is a piece of a template that is included as a part of another template, such as a site header. Template partials can be embedded in multiple templates, simplifying theme creation. Common template partials include:

  • header.php for generating the site’s header
  • footer.php for generating the footer
  • sidebar.php for generating the sidebar

While the above template files are special-case in WordPress and apply to just one portion of a page, you can create any number of template partials and include them in other template files.

WordPress  Common template partials structure


Add the given code to header.php and save this template file:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
    <title><?php bloginfo(‘name’); ?><?php wp_title(); ?></title>
    <meta http-equiv=”Content-Type” content=”<?php bloginfo(‘html_type’); ?>;
    charset=<?php bloginfo(‘charset’); ?>” />
    <meta name=”generator” content=”WordPress <?php bloginfo(‘version’); ?>” />    
    <link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>”
    type=”text/css” media=”screen” />     
    <?php wp_head(); ?>
<div id=”wrapper”>
<div id=”header”>
<h1><a href=”<?php bloginfo(‘url’); ?>”><?php bloginfo(‘name’); ?></a></h1>
<?php bloginfo(‘description’); ?>

This file has opening head and body tag. Included in HTML tag is a head tag (holds stylesheet and Meta tags links). Div tags hold the header content and overall site position.

Navigation Menus (header.php)

  • The Theme’s main navigation should support a custom menu with wp_nav_menu().


Add below code to footer.php and save file:

<div id=”footer”>
Copyright 2018 <a href=”<?php bloginfo(‘url’); ?>”><?php bloginfo(‘name’); ?></a>

Footer defines the bottom part of the site. This theme has copyright announcement now. It adds a permalink of the blog. This is last template file that is called for the site and it closes HTML and body tags.


Add the below code to sidebar.php and save the file:

<div class=”sidebar”>
<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar() ) : else : ?>
 <?php wp_list_pages(‘depth=3&title_li=<h2>Pages</h2>’); ?>
 <li><h2><?php _e(‘Categories’); ?></h2>
     <?php wp_list_cats(‘sort_column=name&optioncount=1&hierarchical=0’); ?>
 <li><h2><?php _e(‘Archives’); ?></h2>
     <?php wp_get_archives(‘type=monthly’); ?>
 <?php get_links_list(); ?> 
<?php endif; ?>

This code is to define and include sidebars like blogroll, archive, category and pages.

Was this article helpful to you? Yes No

How can we help?