Title: enqueue styles for plugin
Last modified: August 19, 2016

---

# enqueue styles for plugin

 *  [christian_gnoth](https://wordpress.org/support/users/christian_gnoth/)
 * (@christian_gnoth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/)
 * i have registered and enqueued my plugin stylesheets accordingly to the description
   on this page:
 * [http://codex.wordpress.org/Function_Reference/wp_enqueue_style](http://codex.wordpress.org/Function_Reference/wp_enqueue_style)
 * but if i call the plugin admin page the stylesheet is not included in the html
   header – i can not found an link entry for this file.
 * the function is called – i have tested it.
 * any idea what could be the problem?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749749)
 * Which action is the enqueue hooked on to?
 * If it’s not hooked onto a specific action how are you specifying when the enqueue
   is run?
 *  Thread Starter [christian_gnoth](https://wordpress.org/support/users/christian_gnoth/)
 * (@christian_gnoth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749810)
 * the function is called. i have checked it – i create a file in the function with
   file_put_contents – the file is created. so the function is called.
 *     ```
       function bbnuke_plugin_add_option_page()
       {
         $bbnuke_admin_page =
         add_menu_page   (                       'baseballNuke Plugin Options', 'baseballNuke', 8, 'bbnuke-option-page',  'bbnuke_plugin_create_option_page', BBNPURL . 'images/baseballNuke_16x16.gif');
         add_submenu_page( 'bbnuke-option-page', 'Players',                     'Players',      8, 'bbnuke-players',      'bbnuke_plugin_create_players_page');
         add_submenu_page( 'bbnuke-option-page', 'Fields',                      'Fields',       5, 'bbnuke-fields',       'bbnuke_plugin_create_fields_page');
         add_submenu_page( 'bbnuke-option-page', 'Schedule',                    'Schedule',     5, 'bbnuke-schedule',     'bbnuke_plugin_create_schedules_page');
         add_submenu_page( 'bbnuke-option-page', 'Tournaments',                 'Tournaments',  5, 'bbnuke-tournaments',  'bbnuke_plugin_create_tournaments_page');
         add_submenu_page( 'bbnuke-option-page', 'Practices',                   'Practices',    5, 'bbnuke-practice',     'bbnuke_plugin_create_practice_page');
         add_submenu_page( 'bbnuke-option-page', 'Game Results',                'Game Results', 5, 'bbnuke-game-results', 'bbnuke_plugin_create_game_results_page');
         add_submenu_page( 'bbnuke-option-page', 'Uninstsll',                   'Uninstall',    5, 'bbnuke-uninstall',    'bbnuke_plugin_uninstall');
   
         add_action( 'admin_print_scripts-' . $bbnuke_admin_page, 'bbnuke_admin_head' );
   
         return;
       }
   
       function  bbnuke_admin_head()
       {
         wp_enqueue_style( 'bbnuke_admin_styles' );
       }
       ```
   
 *     ```
       function bbnuke_admin_init_method()
       {
   
         wp_register_style('bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
       }
   
       add_action( 'admin_init',   'bbnuke_admin_init_method');
       ```
   
 *  Thread Starter [christian_gnoth](https://wordpress.org/support/users/christian_gnoth/)
 * (@christian_gnoth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749873)
 * any idea how to check if the style is registered properly? the enqueue function
   do not returns any value – so there is no chance to check if the call is successfull
   or not.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749881)
 * Are you aware the code you have above will only enqueue the stylesheet when it’s
   the parent page, ie. your main plugin page, not any of the rest(subpages)… are
   you checking the top level page when the enqueue fails? (the bbnuke-option-page
   page).
 * You don’t necessarily need to register the style unless you’re likely to re-use
   it elsewhere… just the enqueue is sufficient if you’re only using it inside the
   plugin..
 * eg.
 *     ```
       wp_enqueue_style( 'bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css' );
       ```
   
 * So you could actually drop the register style code altogether..
 * For checking the registered styles, you can print out the `$wp_styles` var..
 *  Thread Starter [christian_gnoth](https://wordpress.org/support/users/christian_gnoth/)
 * (@christian_gnoth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749888)
 * still not working.
 * I have putted it in
 * add_action( ‘wp_print_styles’, ‘bbnuke_print_styles’);
 *     ```
       function  bbnuke_print_styles()
       {
   
         global $plugin_url;
   
         if ( is_admin() )
         {
       //  wp_register_style('bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
           wp_enqueue_style( 'bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
         }
         else
         {
           wp_register_style('bbnuke_frontend_styles', BBNPURL . 'css/bbnuke-frontend-plugin.php');
           wp_enqueue_style( 'bbnuke_frontend_styles' );
         }
   
         return;
       }
       ```
   
 * but it is not printed.
 * so i putted it in admin_init and the style is printed.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749969)
 * `wp_print_styles` is a front side hook (not the admin area), so it’s not suited..
 * Create hooks for each of your pages..
 *     ```
       $bbnuke_admin_page =
       add_menu_page   (                       'baseballNuke Plugin Options', 'baseballNuke', 8, 'bbnuke-option-page',  'bbnuke_plugin_create_option_page', BBNPURL . 'images/baseballNuke_16x16.gif');
   
       $players_page      =
       add_submenu_page( 'bbnuke-option-page', 'Players',                     'Players',      8, 'bbnuke-players',      'bbnuke_plugin_create_players_page');
   
       $fields_page
       add_submenu_page( 'bbnuke-option-page', 'Fields',                      'Fields',       5, 'bbnuke-fields',       'bbnuke_plugin_create_fields_page');
       ```
   
 * …etc..
 * You can then add actions to each of those pages that should load the stylesheet..
 *     ```
       add_action( 'admin_print_styles-' . $bbnuke_admin_page, 'bbnuke_admin_head' );
       add_action( 'admin_print_styles-' . $players_page, 'bbnuke_admin_head' );
       add_action( 'admin_print_styles-' . $fields_page, 'bbnuke_admin_head' );
       ```
   
 * ..and so on…

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘enqueue styles for plugin’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 6 replies
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/enqueue-styles-for-plugin/#post-1749969)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
