Performance: Header, footer, and sidebar templates
This affects the page load speed and rendering by controlling reusable layout parts that appear on many pages.
Jump into concepts and practice - no test required
<?php get_header(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
<?php /* header, footer, sidebar HTML repeated in every template file */ ?>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual repeated header/footer/sidebar code | More DOM nodes duplicated | Multiple reflows per page | Higher paint cost due to larger DOM | [X] Bad |
| Using get_header(), get_footer(), get_sidebar() | Fewer duplicated DOM nodes | Single reflow per page load | Lower paint cost due to smaller DOM | [OK] Good |
get_header(), get_sidebar(), and get_footer() in a WordPress theme?get_header(), get_sidebar(), and get_footer() are WordPress functions used to include specific parts of a theme.get_sidebar().include_sidebar(), load_sidebar(), or sidebar_include() do not exist in WordPress.<?php get_header(); ?> <main>Content here</main> <?php get_footer(); ?>
get_header(), then outputs main content inside <main>, then calls get_footer(). This means all three parts will appear on the page.get_sidebar(); in your theme file, but the sidebar does not appear on the site. What is the most likely cause?get_sidebar(); includes sidebar.php by default. If this file is missing, nothing will show.get_header(); is not required before sidebar. get_sidebar(); works without parameters. WordPress supports sidebars by default.footer-special.php and include it only on the homepage. Which code snippet correctly includes this custom footer in your theme's index.php?get_footer('special') loads footer-special.php. Without parameters, it loads footer.php.is_front_page() returns true on the homepage. So, use it to load the special footer only there, else load default footer.footer-special.php on homepage and default footer elsewhere. Other options call footers incorrectly or in wrong order.