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
1

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

Leave a Reply

Your email address will not be published. Required fields are marked *