Performance: Custom headers and footers
This affects the page load speed and visual stability by controlling how header and footer content is loaded and rendered.
<?php wp_enqueue_style('custom-header-style', get_template_directory_uri() . '/css/header.css'); ?> <?php wp_enqueue_script('custom-header-script', get_template_directory_uri() . '/js/header.js', [], null, true); ?> <?php get_header(); ?> <header> <h1>My Site</h1> </header> <?php get_footer(); ?>
<?php get_header(); ?> <!-- Inline styles and scripts inside header --> <header> <style>body {background: #fff;}</style> <script>console.log('header loaded');</script> <h1>My Site</h1> </header> <?php get_footer(); ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styles/scripts in header/footer | Low DOM nodes | Multiple reflows due to blocking | High paint cost from layout shifts | [X] Bad |
| External CSS/JS enqueued properly | Low DOM nodes | Single reflow | Low paint cost with stable layout | [OK] Good |
wp_head and wp_footer hooks in WordPress?wp_head and wp_footer allow adding extra code to header and footer areas.wp_footer hook in your theme's functions.php?wp_footer hook is used with add_action to add code to the footer.add_action('wp_footer', function() { ... }); which is correct syntax to add inline script.functions.php:add_action('wp_head', function() { echo '<meta name="custom" content="123">'; });wp_head hook inserts code inside the <head> tag of the HTML document.functions.php:add_action('wp_footer', function() { echo '<div>Footer Text</div>'; });wp_footer() function must be called in the theme's footer.php to output footer hook content.wp_footer() is missing, the hook callback won't run and content won't show.wp_footer() function in its footer.php file -> Option Afunctions.php?is_front_page() inside wp_head hook to add header message only on homepage.wp_footer hook without condition to add footer copyright on every page.Pass the test and this pattern moves unknown