{"id":248,"date":"2025-07-27T06:40:55","date_gmt":"2025-07-27T06:40:55","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=248"},"modified":"2025-07-27T06:54:06","modified_gmt":"2025-07-27T06:54:06","slug":"anatomy-of-a-theme-header-php-footer-php-and-sidebar-php","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=248","title":{"rendered":"Anatomy of a Theme: header.php, footer.php and sidebar.php"},"content":{"rendered":"\n<p>In WordPress, themes are modular. The files <code>header.php<\/code>, <code>footer.php<\/code>, and <code>sidebar.php<\/code> form the <strong>basic structure of a page layout<\/strong>. Together, they help break up the page into reusable components.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Anatomy of a Theme<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"> Common Template Parts:<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>File<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>header.php<\/code><\/td><td>Top section: metadata, site title, logo, navigation, etc.<\/td><\/tr><tr><td><code>footer.php<\/code><\/td><td>Bottom section: copyright, footer nav, scripts, etc.<\/td><\/tr><tr><td><code>sidebar.php<\/code><\/td><td>Sidebar: widgets, categories, search, recent posts, etc.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <code>header.php<\/code><\/h3>\n\n\n\n<p><strong>Purpose<\/strong>: Contains everything from the top of the page to the start of content\u2014like <code>&lt;!DOCTYPE&gt;<\/code>, <code>&lt;head&gt;<\/code>, logo, menu.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;!DOCTYPE html&gt;<br>&lt;html &lt;?php language_attributes(); ?&gt;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=\"&lt;?php bloginfo('charset'); ?&gt;\"&gt;<br>  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;<br>  &lt;title&gt;&lt;?php bloginfo('name'); ?&gt;&lt;\/title&gt;<br>  &lt;?php wp_head(); ?&gt;<br>&lt;\/head&gt;<br>&lt;body &lt;?php body_class(); ?&gt;&gt;<br>  &lt;header&gt;<br>    &lt;h1&gt;&lt;a href=\"&lt;?php echo home_url(); ?&gt;\"&gt;&lt;?php bloginfo('name'); ?&gt;&lt;\/a&gt;&lt;\/h1&gt;<br>    &lt;p&gt;&lt;?php bloginfo('description'); ?&gt;&lt;\/p&gt;<br>    &lt;nav&gt;<br>      &lt;?php wp_nav_menu(['theme_location' =&gt; 'main-menu']); ?&gt;<br>    &lt;\/nav&gt;<br>  &lt;\/header&gt;<br><\/code><\/pre>\n\n\n\n<p> In your main template (<code>index.php<\/code>, <code>page.php<\/code>, etc.), load it with:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php get_header(); ?><br><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"> 2. <code>footer.php<\/code><\/h3>\n\n\n\n<p><strong>Purpose<\/strong>: Bottom part of the page. Contains closing tags, footer widgets, and <code>wp_footer()<\/code> (important for plugins and scripts).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code> &lt;footer&gt;<br>    &lt;p&gt;&amp;copy; &lt;?php echo date('Y'); ?&gt; &lt;?php bloginfo('name'); ?&gt;. All rights reserved.&lt;\/p&gt;<br>  &lt;\/footer&gt;<br>  &lt;?php wp_footer(); ?&gt;<br>&lt;\/body&gt;<br>&lt;\/html&gt;<br><\/code><\/pre>\n\n\n\n<p> Include it in templates using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php get_footer(); ?><br><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"> 3. <code>sidebar.php<\/code><\/h3>\n\n\n\n<p><strong>Purpose<\/strong>: Optional side panel, usually used for widgets, search, recent posts, etc.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;aside id=\"sidebar\" class=\"widget-area\"&gt;<br>  &lt;?php if ( is_active_sidebar( 'main-sidebar' ) ) : ?&gt;<br>    &lt;?php dynamic_sidebar( 'main-sidebar' ); ?&gt;<br>  &lt;?php else : ?&gt;<br>    &lt;p&gt;Add widgets via Appearance &gt; Widgets.&lt;\/p&gt;<br>  &lt;?php endif; ?&gt;<br>&lt;\/aside&gt;<br><\/code><\/pre>\n\n\n\n<p>\u2705 <strong>Register Sidebar in <code>functions.php<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>function mytheme_widgets_init() {<br>  register_sidebar([<br>    'name' => 'Main Sidebar',<br>    'id' => 'main-sidebar',<br>    'before_widget' => '&lt;section class=\"widget\">',<br>    'after_widget'  => '&lt;\/section>',<br>    'before_title'  => '&lt;h2 class=\"widget-title\">',<br>    'after_title'   => '&lt;\/h2>',<br>  ]);<br>}<br>add_action('widgets_init', 'mytheme_widgets_init');<br><\/code><\/pre>\n\n\n\n<p> Add in templates using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php get_sidebar(); ?&gt;<br><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"> Summary Diagram<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[ header.php ]<br>    \u2191<br>[ index.php \/ page.php \/ single.php ]<br>    \u2193<br>[ sidebar.php ]        [ footer.php ]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,2],"tags":[],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-unit-5","category-wordpress"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=248"}],"version-history":[{"count":2,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/248\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}