Admin Theme customization

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 */
}

Related posts

Leave a Reply

1 comment

  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' );
    }