How to properly add CSS in WordPress

December 3rd, 2010 |

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');

There are no comments yet

Leave a Reply

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

*

Time: 0.00069 sec.

Memory: 267.41 kb