Performance: Child themes and overrides
MEDIUM IMPACT
This affects page load speed and rendering by controlling which CSS and PHP files load and how many files the browser requests.
<?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 |