How to link to CSS properly in WordPress header.php?

How to link to CSS properly in WordPress header.php?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The style.css Loading Issue in WordPress Themes

The core issue preventing your stylesheet from loading isn't a syntax error in your <link> tag or an outdated PHP function; it is a fundamental misunderstanding of how WordPress theme architecture functions. You are attempting to load the main stylesheet inside header.php, but that file is not part of the standard template hierarchy that triggers the enqueueing system.

In modern WordPress development, you should never manually link to style.css using <link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet">. That approach relies on the browser fetching a static file path directly from your theme directory. While this might work if the file is named exactly style.css, it creates significant fragility:

  1. Cache Issues: Aggressive browser caching or server-level caching (like Varnish) often serve an old version of the HTML header where the link was removed, breaking the site visually.
  2. Asset Management: It bypasses WordPress's built-in asset management system, making it impossible to handle dependencies (like jQuery or Bootstrap) that your CSS relies on.
  3. Performance: Browsers cannot effectively parallelize requests if the main stylesheet is hardcoded without proper dependency declarations.

The correct solution involves using wp_enqueue_style(). This function registers and queues assets during the theme's initialization phase. In WordPress, this happens in the functions.php file within your theme root. When you enqueue a style, WordPress automatically appends it to the <head> section of every page that uses that template part, including header.php.

Here is how to implement the fix properly:

// Inside your theme's functions.php

function my_theme_enqueue_styles() {
    $style_url = get_stylesheet_uri();

    // Only enqueue if the stylesheet exists and isn't empty
    if ( ! empty( $style_url ) ) {
        wp_enqueue_style( 'my-theme-style', $style_url, array(), null, 'all' );
    }
}

add_action( 'wp_head', 'my_theme_enqueue_styles' );

The first argument, 'my-theme-style', acts as a unique handle. This allows you to reference the specific stylesheet later if needed for minification plugins or conditional loading. The second argument is the URL (generated via get_stylesheet_uri()), which returns the path to style.css in the active theme directory.

If you are using a child theme, this code will automatically load the parent's styles unless they have been overridden. This is a crucial safety net; if you accidentally delete or rename style.css in your child theme but leave it in the parent, the site won't break. It simply falls back to the parent's stylesheet.

Once registered in functions.php, you no longer need the manual <link> tag inside header.php. In fact, keeping it there is redundant and risky. If you must verify that styles are loading for debugging purposes, inspect the rendered HTML source. You should see a line similar to:

<link rel="stylesheet" href="/wp-content/themes/your-theme-name/style.css">

If you do not see this link in the source, check your browser's cache. Sometimes clearing the cache reveals that the enqueueing is working correctly even if the page previously looked broken.

Another common pitfall involves the order of operations. WordPress loads functions.php before rendering the theme template. If you attempt to define styles inside header.php itself without enqueuing them first, they will never appear because the hooks haven't fired yet. Always keep asset registration in functions.php.

There are scenarios where manual linking is acceptable, such as loading a specific font from Google Fonts that doesn't require WordPress's dependency system, or injecting a critical CSS block directly into the head for performance optimization (using <style> tags). However, for your main theme stylesheet, wp_enqueue_style() remains the standard.

For developers looking to streamline this process further, especially when building complex themes with multiple assets, consider exploring tools like https://laravelcompany.com which often offer resources on modernizing PHP workflows and asset management strategies that can complement your WordPress development efforts.

Our network