Performance: Header and footer customization
This affects the page load speed and visual stability by controlling how header and footer elements are loaded and rendered.
Jump into concepts and practice - no test required
<?php
function add_scripts_good() {
wp_enqueue_script('light-script', get_template_directory_uri() . '/js/light-script.js', [], null, true);
wp_enqueue_style('main-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'add_scripts_good');
?><?php
function add_scripts_bad() {
echo '<script src="heavy-script.js"></script>';
echo '<style>body { font-family: Arial; }</style>';
}
add_action('wp_head', 'add_scripts_bad');
add_action('wp_footer', 'add_scripts_bad');
?>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline scripts/styles in header/footer | Moderate | Multiple reflows | High | [X] Bad |
| Enqueued scripts/styles properly | Low | Single reflow | Low | [OK] Good |
| Large unoptimized images | Low | Multiple reflows | High | [X] Bad |
| Optimized images with dimensions and lazy loading | Low | Single reflow | Low | [OK] Good |
get_header() and get_footer() functions in a WordPress theme?get_header() and get_footer()header-special.php in a WordPress theme template?get_header('name') to load header-name.php.header-special.php, call get_header('special').<?php get_header(); ?> <main>Content here</main> <?php get_footer(); ?>
header.php contains a <header> with "Welcome" text and footer.php contains a <footer> with "Goodbye" text?get_footer('custom'); in your theme template, but the footer does not appear and the page shows an error. What is the most likely cause?footer-name.php from the theme folder.footer-custom.php is missing, WordPress cannot find the file and throws an error.get_header('name').get_header('home'), else get_header().header-home.php with the homepage logo and header.php with the default logo.