Why is style.css not being enqueued?

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.

Topic wp-enqueue-style wp-register-style css Wordpress

Category Web


Minor nitpick on Arun's answer above. Like they said, you should enqueue it in the functions.php file, but it is probably better to define and call it anonymously within the add_action function, since you are not calling it anywhere else. That way, you avoid adding it to the global namespace.

add_action('wp_enqueue_scripts', function () {
    wp_enqueue_style('style', get_stylesheet_uri());
});

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() );

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.


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.