1

I followed instruction on the wordpress codex site on creating an admin theme via a plugin. I activated the plugin, but my stylesheet isn't being included in the <head>..

Here's my code:

add_action( 'admin_init', 'kd_plugin_admin_init' );
add_action( 'admin_menu', 'kd_plugin_admin_menu' );

function kd_plugin_admin_init() {
   /* Register our stylesheet. */
   wp_register_style( 'kdPluginStylesheet', WP_PLUGIN_URL . '/admin-theme.css' );
}

function kd_plugin_admin_menu() {
   /* Register our plugin page */
   $page = add_submenu_page( 'edit.php', 
                             __( 'KD Plugin', 'kdPlugin' ), 
                             __( 'KD Plugin', 'kdPlugin' ),
                             'administrator',
                             __FILE__, 
                             'kd_plugin_manage_menu' );

   /* Using registered $page handle to hook stylesheet loading */
   add_action( 'admin_print_styles' . $page, 'kd_plugin_admin_styles' );
}

function kd_plugin_admin_styles() {
   /*
    * It will be called only on your plugin admin page, enqueue our stylesheet here
    */
   wp_enqueue_style( 'kdPluginStylesheet' );
}

function kd_plugin_manage_menu() {
   /* Output our admin page */
}
1
  • do you want to use your admin theme only on your plugin's page?
    – Mamaduka
    Aug 26, 2011 at 19:28

1 Answer 1

1

You are missing the hyphen in your admin_print_styles hook.

function kd_plugin_admin_menu() {
   /* Register our plugin page */
   $page = add_submenu_page( 'edit.php', 
                             __( 'KD Plugin', 'kdPlugin' ), 
                             __( 'KD Plugin', 'kdPlugin' ),
                             'administrator',
                             __FILE__, 
                             'kd_plugin_manage_menu' );

   /* Using registered $page handle to hook stylesheet loading */
   add_action( 'admin_print_styles-' . $page, 'kd_plugin_admin_styles' );
}
2
  • I just added the hyphen and actually tried it with the hyphen before, but still nothing...
    – MF1
    May 27, 2011 at 11:49
  • I didn't tested the code but it was just hyphen that I found while going through your code, I will test the code as soon as I get on my dev machine and will let you know. May 27, 2011 at 12:24

Your Answer

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

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