WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] help with IE conditional stylesheet enqueue (4 posts)

  1. AngelEyes
    Member
    Posted 2 years ago #

    Hey guys,
    This something i put together to in my functions.php for enqueuing an IE stylesheet only when wordpress detects that the user is on IE.

    I saw that there was an IE global variable so I tried to make use of that. I'm not getting any errors when I run this, buts its not enqueuing the stylesheet as I hoped. Anyone have any idea what the problem is?

    thanks for any help

    $bloginfo = get_bloginfo('template_url');
    if ( !function_exists( 'StyleLoader' ) ) {
    	function StyleLoader( $bloginfo ) {
    		if ( !is_admin() ) {
    			global $is_IE;
    			if ( $is_IE ) {
    				wp_register_style('ieStyle', $bloginfo . '/css/ieStyle.css', array(), '1.0', 'screen');
    				wp_enqueue_style('ieStyle');
    			}
    		}
    	}
    }
    add_action('wp_head', 'StyleLoader');
  2. AngelEyes
    Member
    Posted 2 years ago #

    i tried doing a print_r($is_IE); on my IE dev machine and it returned true...

    ive checked the source and its not including anything in the header as i would expect it to.

  3. AngelEyes
    Member
    Posted 2 years ago #

    so i took out the $bloginfo bit and just hard coded the path to the style sheet in my Wp_register_Style function.

    Its still not enqueuing the style. I can echo stuff inside the is_IE if statement and it works. it seems to be something in the register or enqueue functions..

  4. AngelEyes
    Member
    Posted 2 years ago #

    To all those interested:

    my mistake was using add_action('wp_head', 'StyleLoader');

    if I had paid attention to the codex I would have seen that I needed to hook into wp_print_styles ... for some reason wp_head wasn't groovy.

    so this works:

    if ( !function_exists( 'StyleLoader' ) ) {
    	function StyleLoader()  {
    		if ( !is_admin() ) {
    			global $is_IE;
    			if ( $is_IE ) {
    				wp_register_style( 'ieStyle', 'http://url.com/css/ieStyle.css', array(), '1.0' );
    				wp_enqueue_style( 'ieStyle' );
    			}
    		}
    	}
    }
    add_action('wp_print_styles', 'StyleLoader');

Topic Closed

This topic has been closed to new replies.

About this Topic