Possible Duplicate:
Where is the right place to register/enqueue scripts & styles

When I enqueue a css style in a plugin like so:

function add_my_stylesheet() 
    wp_enqueue_style( 'myCSS', plugins_url( '/css/myCSS.css', __FILE__ ) );

add_action('init', 'add_my_stylesheet');

Is 'init' the correct action to use? It works fine. Is there any reason not to do it this way? Is this the standard way? I want to follow the best practices.

Thank you.


  • Do you want to enqueue style on plugin's options page? – Mamaduka Sep 3 '11 at 7:11
  • if you only have 1 wp_enqueue_style, just add it directly in your plugin, no need to add any function or add_action. – Sean Lee Sep 3 '11 at 17:31
  • @Sean Lee bad advice. It is strongly recommended to enqueue only inside appropriate hooks. It is also commonly recommended to not run any code during plugin load, other than hooking function/methods for executing code later. – Rarst Sep 5 '11 at 10:52
  • Agree with you Rarst in general, especially when there are multiple of them. – Sean Lee Sep 6 '11 at 3:27

You can use admin_print_styles for your hook, this is the preferred method for adding a style to your plugin or admin page.

add_action('admin_print_styles', 'add_my_stylesheet');

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