Question

I got a pretty basic theme and just found out my style.css file doesn't get loaded into the <head>. I already searched around but can't find out, why it's not loading.

I inspected the global $wp_styles object already but couldn't find anything:

function style_test() 
{ 
    $wp_styles = new WP_Styles();

    echo '<pre>'; 
        // $wp_styles->enqueue == completely empty
        print_r( $wp_styles->registered ); 
    echo '</pre>'; 
} 
add_action( 'wp_print_scripts', 'style_test', 0 );

Inside the object i also can't find my registered/enqueued stylesheets (they get loaded), so i guess i'm doing something wrong on inspecting this too. Any ideas?

Note:
If i enqueue it manually, my style.css file get's loaded. Just the automatic loading doesn't work. Further more i can access the file with get_theme_data( TEMPLATEPATH.'/style.css' ); without a problem.

Was it helpful?

Solution

Theme stylesheets aren't usually enqueued, they're normally loaded using..

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />

So naturally you don't see them(it) in the styles array..

You can of course(if you prefer) use an enqueue instead.

OTHER TIPS

The recommended way to do it is by enqueue-ing style.css in the functions.php of the theme.

Add this to functions.php

 /**
 * Load CSS and JS the right way
 */
function myprefix_load_css_and_js() {
    wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'myprefix_load_css_and_js' );

You can refer this in the WordPress theme handbook here and see examples here.

although its already solved i think this will also help someone.

You can load style.css by adding this line of code in any single page or custom template.

wp_enqueue_style('style', get_stylesheet_uri() );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top