Performance: Child themes and overrides
This affects page load speed and rendering by controlling which CSS and PHP files load and how many files the browser requests.
Jump into concepts and practice - no test required
<?php
// In child theme functions.php
function load_parent_and_child_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style'));
}
add_action('wp_enqueue_scripts', 'load_parent_and_child_styles');<?php
// In child theme functions.php
function load_parent_and_child_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');
wp_enqueue_style('parent-style-dup', get_template_directory_uri() . '/style.css'); // duplicate load by mistake
}
add_action('wp_enqueue_scripts', 'load_parent_and_child_styles');| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicate CSS loading in child theme | No extra DOM nodes | Triggers multiple reflows due to CSS changes | Higher paint cost due to style recalculation | [X] Bad |
| Proper enqueue of parent and child styles | No extra DOM nodes | Single reflow after styles load | Lower paint cost with minimal style recalculation | [OK] Good |
| Full template file override without changes | No direct DOM impact | No reflows but slower server response delays DOM rendering | Paint delayed by slower HTML delivery | [!] OK |
| Selective template override or hooks | No direct DOM impact | No reflows, faster server response | Paint happens sooner with faster HTML | [OK] Good |
style.css to link it to its parent theme?style.css must have a Template line naming the parent theme folder.functions.php snippet in a child theme, what will happen?<?php
function child_theme_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style'));
}
add_action('wp_enqueue_scripts', 'child_theme_styles');
?>header.php file in your child theme. Which is the correct way to do this?header.php to child theme and editing it overrides the parent's version.