1

I'm writing a plugin using WPPB, and can't seem to get my CSS to enqueue just on my plugin's admin page.

I've got a function in my class-{plugin}-admin.php file that should enqueue the script. And I can see that it's running with the right file path for the css file, but the script doesn't get enqueued for some reason, and I can't find an error. I put error_logs to confirm that the jo_page_enqueue_styles function is in fact only running on the correct pages, but still no stylesheet.

public function jo_page_enqueue_styles() {

    error_log('jo_page_enqueue_styles ran');

    error_log('style path is: ' . plugin_dir_url( __FILE__ ) . 'css/jumpoff-admin-page.css');

    wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/jumpoff-admin-page.css', array(), $this->version, 'all' );

}

This function is run by this hook in class-{plugin}.php inside inside the define_admin_hooks function,

$this->loader->add_action( 'admin_print_styles-'.'toplevel_page_jumpoff' , $plugin_admin, 'jo_page_enqueue_styles' );

Any ideas? Am I going about this all wrong? Thanks.

1

Make sure you enqueue using a unique name. Since this is custom page the default is to enqueue styles for the plugin under the same name.

wp_enqueue_style( {unique name}, ...

|improve this answer|||||
  • Ha, I just figured it out, and came here to resolve, and I found this answer. This is exactly what it was. I was using the same name for an earlier enqueue of a general admin stylesheet. – jqlee85 Dec 23 '15 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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