Title: How to load conditional javascript through functions.php?
Last modified: August 20, 2016

---

# How to load conditional javascript through functions.php?

 *  [sixfootjames](https://wordpress.org/support/users/sixfootjames/)
 * (@sixfootjames)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/how-to-load-conditional-javascript-through-functionsphp/)
 * Hi,
 * I managed to find my answer to find part of my question in this function [from another post](http://wordpress.org/support/topic/how-to-load-specific-java-script-on-specific-page?replies=9):
 *     ```
       function scripts() {
       if ( !is_admin() ) { // this if statement will insure the following code only gets added to your wp site and not the admin page cause your code has no business in the admin page right unless that's your intentions
       	// jquery
       		wp_deregister_script('jquery'); // this deregisters the current jquery included in wordpress
       		wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false); // this registers the replacement jquery
       		wp_enqueue_script('jquery'); // you can either let wp insert this for you or just delete this and add it directly to your template
       	// your own script
       		wp_register_script('yourscript', ( get_bloginfo('template_url') . '/yourscript.js'), false); //first register your custom script
       		wp_enqueue_script('swfobject'); // then let wp insert it for you or just delete this and add it directly to your template
               // just in case your also interested
       		wp_register_script('yourJqueryScript', ( get_bloginfo('template_url') . '/yourJquery.js'), array('jquery')); // this last part-( array('jquery') )is added in case your script needs to be included after jquery
       		wp_enqueue_script('yourJqueryScript'); // then print. it will be added after jquery is added
       	}
       }
       add_action( 'wp_print_scripts', 'scripts'); // now just run the function
       ```
   
 * What I’d like to know now however is how to add a conditional statement to the
   functions.php file to load only certain scripts for IE9-only browsers please?
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [sixfootjames](https://wordpress.org/support/users/sixfootjames/)
 * (@sixfootjames)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/how-to-load-conditional-javascript-through-functionsphp/#post-2925677)
 * Not to worry, I found this little beauty for detecting browser version without
   having to resort to user-agent sniffing
 * [https://gist.github.com/527683](https://gist.github.com/527683)

Viewing 1 replies (of 1 total)

The topic ‘How to load conditional javascript through functions.php?’ is closed 
to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [ie](https://wordpress.org/support/topic-tag/ie/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [sixfootjames](https://wordpress.org/support/users/sixfootjames/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/how-to-load-conditional-javascript-through-functionsphp/#post-2925677)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
