How to add comment on scripts using function in wordpress?

this is the code im using to call script if the browser is ie

<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <style type="text/css"> .clear { zoom: 1;display: block;} </style> <![endif]-->

but how can i add this on function.php as normal way we do this to call the js

Read More
wp_register_script('html5js', ("http://html5shiv.googlecode.com/svn/trunk/html5.js"), false, '1.3.2');
wp_enqueue_script('html5js');

and i dont want to statically insert the code on header is there any other way to generate comment?

Related posts

1 comment

  1. There is a generic way to use conditional comments – for styles. But unfortunately not for scripts until #16024 will be fixed. The details are described in this answer.

    To make your themes scripts filterable you could use a callback on wp_print_scripts and apply a custom filter in there.

    /**
     * prints a conditional comments wrapped script
     *
     * @wp-hook wp_print_scripts
     * @return void
     */
    add_action( 'wp_print_scripts', 'wpse_135545_enqueue_print_script' );
    function wpse_135545_enqueue_print_script() {
    
        $params = apply_filters(
            'wpse_135545_enqueue_print_script',
            array(
                'url'     => 'http://html5shiv.googlecode.com/svn/trunk/html5.js',
                'version' => '1.0',
                'cond'    => 'IE'
            )
        );
    
        if ( empty( $params[ 'url' ] ) )
            return;
    
        printf(
            "<!--[if %s]>nt<script src="%s"></script>n<![endif]-->n",
            $params[ 'cond' ],
            add_query_arg( 'v', $params[ 'version' ], $params[ 'url' ] )
        );
    }
    

    A plugin or child theme author can now handle this by either changing the parameter via the filter or remove the hook completely. (By the way, the version parameter does not make sense on combination with a url to the trunk. You may consider to link to a fix version of the script.)

Comments are closed.