In WordPress, themes are modular. The files header.php, footer.php, and sidebar.php form the basic structure of a page layout. Together, they help break up the page into reusable components.
Anatomy of a Theme
Common Template Parts:
| File | Purpose |
|---|---|
header.php | Top section: metadata, site title, logo, navigation, etc. |
footer.php | Bottom section: copyright, footer nav, scripts, etc. |
sidebar.php | Sidebar: widgets, categories, search, recent posts, etc. |
1. header.php
Purpose: Contains everything from the top of the page to the start of content—like <!DOCTYPE>, <head>, logo, menu.
Example:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1>
<p><?php bloginfo('description'); ?></p>
<nav>
<?php wp_nav_menu(['theme_location' => 'main-menu']); ?>
</nav>
</header>
In your main template (index.php, page.php, etc.), load it with:
<?php get_header(); ?>
2. footer.php
Purpose: Bottom part of the page. Contains closing tags, footer widgets, and wp_footer() (important for plugins and scripts).
Example:
<footer>
<p>© <?php echo date('Y'); ?> <?php bloginfo('name'); ?>. All rights reserved.</p>
</footer>
<?php wp_footer(); ?>
</body>
</html>
Include it in templates using:
<?php get_footer(); ?>
3. sidebar.php
Purpose: Optional side panel, usually used for widgets, search, recent posts, etc.
Example:
<aside id="sidebar" class="widget-area">
<?php if ( is_active_sidebar( 'main-sidebar' ) ) : ?>
<?php dynamic_sidebar( 'main-sidebar' ); ?>
<?php else : ?>
<p>Add widgets via Appearance > Widgets.</p>
<?php endif; ?>
</aside>
✅ Register Sidebar in functions.php:
function mytheme_widgets_init() {
register_sidebar([
'name' => 'Main Sidebar',
'id' => 'main-sidebar',
'before_widget' => '<section class="widget">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
]);
}
add_action('widgets_init', 'mytheme_widgets_init');
Add in templates using:
<?php get_sidebar(); ?>
Summary Diagram
[ header.php ]
↑
[ index.php / page.php / single.php ]
↓
[ sidebar.php ] [ footer.php ]