Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

-Laxmidi

share|improve this question
    
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
add comment

marked as duplicate by Rarst Sep 5 '11 at 10:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 1 down vote accepted

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');
share|improve this answer
1  
Why WP_PLUGIN_URL and not plugins_url()? EDIT: Just reading here (codex.wordpress.org/Determining_Plugin_and_Content_Directories) that the contants are intended for core use, not plugins. –  tollmanz Sep 5 '11 at 5:01
    
You're right, not just for SSL but if the plugin is not in the default plugins directory, removing it. –  Wyck Sep 5 '11 at 5:50
add comment

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