Why Your Child Theme style.css Isn't Applying (And How to Fix It)
If you've just created a child theme for Alpine and are staring at a browser where your custom CSS changes in the child file are ignored, but edits to the parent's style.css take effect immediately, you aren't missing a configuration step. The issue lies in how WordPress handles the loading order of stylesheets.
The code snippet you provided for the child theme's functions.php is actually correct:
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
However, this function only enqueues the parent stylesheet. It does not automatically tell WordPress to load your child theme's style.css. In older versions of WordPress or with manual enqueueing logic, you had to explicitly queue the child styles after the parent styles. While modern themes and frameworks often handle this automatically via their own enqueue hooks, a custom child theme relies on its own header declaration.
WordPress looks for the standard comment block in the style.css file to identify a stylesheet's priority and dependencies. If your child theme's style.css lacks specific headers declaring it as a dependency of the parent, WordPress loads both files independently. When two CSS files are loaded without a defined order, or if they share identical priority values, the browser applies them based on source order. Since the parent theme is typically enqueued first, any styles in the child theme that you intended to override might be getting re-compiled or simply ignored due to specificity issues rather than loading order.
To ensure your changes take precedence, the most robust solution is to explicitly declare the dependency in your child style.css. Add the following lines immediately after the standard header comments:
/*
Theme Name: Alpine Child
Template: Alpine
*/
/*
The parent theme style is loaded by default.
To ensure our child styles override correctly, we rely on
the browser's natural cascade order or explicitly set a higher priority
if using wp_enqueue_style with numeric arguments.
For pure CSS files in /wp-content/themes/alpine-child/style.css,
you do not need to enqueue them manually like JS scripts.
WordPress automatically loads the child theme's style.css
BEFORE the parent theme's style.css when the child is active.
*/
Wait, there is a nuance here that often trips developers up. When WordPress activates a child theme, it automatically includes the child's style.css before the parent's style.css. This means your CSS should theoretically override the parent's rules if you use the same selectors with equal or higher specificity.
If your changes are not showing up, check for these common pitfalls:
- Specificity Wars: You might be trying to change a color using
.btn { background: red; }when the parent theme already has.btn { background: #0073aa; }. If the parent uses an ID selector or a class with additional modifiers (e.g.,.btn.primary), your simple class won't win. You may need to use!importantor increase specificity carefully, though increasing specificity is generally preferred for maintainability. - Enqueue Conflicts: Your current
functions.phpenqueues the parent style viawp_enqueue_style. This function expects a handle name. If you are manually enqueueing the child style elsewhere in your theme (which is rare but possible), you might be creating two separate handles with the same name, causing one to overwrite the other unpredictably. - Missing Child Style Enqueue: In some custom setups, if the parent theme's
functions.phpexplicitly checks for a child theme and only enqueues the parent, it might skip the child unless you define the child's handle. However, standard WordPress behavior loads the childstyle.cssautomatically without needingwp_enqueue_stylecalls infunctions.phpfor CSS alone.
If you are still seeing no changes after clearing your browser cache (Ctrl+F5) and ensuring no conflicting plugins are injecting styles, try adding a version string to the parent style enqueue call to force a hard reload:
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array(), '1.0' );
And ensure your child theme's style.css is actually being read by checking if the file exists in the active directory and contains valid syntax. Sometimes a stray semicolon or missing closing brace at the end of the file can cause the entire stylesheet to be parsed as invalid, resulting in no styles loading.
For complex projects where you need fine-grained control over asset loading, consider using a build tool like Webpack or Vite to bundle your CSS and inject it with specific handles, ensuring strict dependency management. This approach eliminates ambiguity about load order and specificity.