Use wp_enqueue_style

A few months ago Chris Scott gave a presentation on ‘proper’ WordPress plugin development. It was full of great stuff so I thought I’d pass along a small slice of it here.

Instead of writing your CSS and JS to your theme’s header.php, or echo’ing it out in a function call; use WP’s wp_enqueue_style and wp_enqueue_script functions respectively. wp_enqueue_script is really handy to check for/load dependent scripts (jQuery, Scriptalicious, etc) and wp_enqueue_style even works on conditional CSS…

wp_enqueue_style(
'ie7-style',
get_template_directory_uri()  . '/ie7.css'
);
global $wp_styles;
$wp_styles->add_data( 'ie7-style', 'conditional', 'lte IE 7′ );

Chris’ article on condtional CSS is here:
http://iamzed.com/2010/01/07/using-wordpress-wp_enqueue_style-with-conditionals/

and his full presentation is here:
http://www.slideshare.net/iamzed/youre-doing-it-wrong-wordcamp-orlando

Leave a Reply

Your email address will not be published. Required fields are marked *

*