Notice that the wp_enqueue_style is not being called correctly!

The problem is that the wp_enqueue_style() call is inside of the category_collapse() member function of the CategoryCollapse() class, and the CategoryCollapse() class is being instantiated by a callback hooked into the plugins_loaded action hook.

That means that the wp_enqueue_style() function is attempting to execute at the plugins_loaded hook, which fires before init, wp_enqueue_scripts, and admin_enqueue_scripts.

To fix, replace this:

wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );

…with this:

function wpse49339_enqueue_styles() {
    wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
}
add_action( 'wp_enqueue_scripts', 'wpse49339_enqueue_styles' );

That way, the wp_enqueue_style() call will be hooked into wp_enqueue_scripts instead of firing directly at plugins_loaded.

Leave a Comment