How to properly add CSS in WordPress

It is important that the styles should not be added in hard-code way. Right way to include CSS is using the standard functions of WordPress wp_enqueue_style. It is a safe way that will save you from future troubles. Moreover, it is more convenient and makes your code more readable.

Using wp_enqueue_style
wp_enqueue_style($handle, $src, $deps, $ver, $media);
Example
function my_init_method() {
wp_enqueue_style(‘theme-print’,
get_template_directory_uri() . ‘/print.css’,
false, false, ‘print’);
}
add_action(‘init’, ‘my_init_method’);
Add IE7.CSS
// If IE7 add the Internet Explorer 7 specific stylesheet
global $wp_styles;
wp_enqueue_style(‘ie7-style’, THEME_CSS . ‘/ie7.css’);
$wp_styles->add_data(‘ie7-style’, ‘conditional’, ‘lte IE 7’);

Leave a Comment