6

I'm trying to load a custom stylesheet (for the front-end, not admin area) via plugin. As near as I can tell, I'm doing things the way the Codex says is correct, but my CSS doesn't get loaded. This is what I have:

/*
 * Load stylesheets, etc.
 */
function cl_chanimal_scripts() {

    //Register CSS
    wp_register_style('cl-chanimal-styles', plugins_url('css/cl-chanimal-styles.css', __FILE__));

    //Use it!
    wp_enqueue_style ( 'cl-chanimal-styles' );
}
add_action( 'wp_enqueue_scripts', 'cl_chanimal_scripts' );

Am I using the wrong action hook? It is possible to load front-end styles via plugin, is it not?

1 Answer 1

9

First thing to mention is that you don't need to use wp_register_style if enqueuing within the same function. You can replace it with wp_enqueue_style and remove the duplicate.

As for why your stylesheet isn't loading, start by checking the file path. Try this instead:

wp_enqueue_style('cl-chanimal-styles', plugin_dir_url( __FILE__ ) . 'css/cl-chanimal-styles.css' );

https://codex.wordpress.org/Function_Reference/plugin_dir_url

1
  • 2
    That did it! I originally had code like yours, but I was using plugins_url() instead of plugin_dir_url(). Both functions sound like they do the same thing. Thanks!
    – eljefejb
    Jul 1, 2015 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.