Title: adding conditionals to load script
Last modified: August 19, 2016

---

# adding conditionals to load script

 *  [is_activated](https://wordpress.org/support/users/is_activated/)
 * (@is_activated)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/adding-conditionals-to-load-script/)
 * I have added conditional tags to javascript loading function
 *     ```
       if (!is_admin()) add_action( 'wp_print_scripts', 'theme_javascript_home' );
       function theme_javascript_home( ) {
       wp_reset_query();
       if (is_home()) {
       wp_enqueue_script( 'script1', get_bloginfo('template_directory').'/js/script1.js', array( 'jquery' ) );
       }
       }
       if (!is_admin()) add_action( 'wp_print_scripts', 'theme_javascript_single' );
       function theme_javascript_single( ) {
       if (is_single()) {
       wp_enqueue_script( 'script2', get_bloginfo('template_directory').'/js/script2.js');
       }
       }
       remove_action('wp_head', 'wp_print_scripts');
       add_action('wp_footer', 'wp_print_scripts', 5);
       ```
   
 * Why I did it? So script1 (home page) will be loaded only when browsing home page.
   As many visitors get to the single page first and it takes a few clicks untill
   they get to the home page. It doesn’t load jquery, which I use on the home page
   only, untill visitor gets to the home page.
 * Firebug shows difference.
 * **Would someone comment on this practice. Is it good ?**
    Also you can see that
   using function loads javascript in the footer. Thank you

Viewing 1 replies (of 1 total)

 *  [dahousecat_net](https://wordpress.org/support/users/dahousecat_net/)
 * (@dahousecat_net)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/adding-conditionals-to-load-script/#post-1096691)
 * For admin pages use: admin_print_scripts

Viewing 1 replies (of 1 total)

The topic ‘adding conditionals to load script’ is closed to new replies.

## Tags

 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * 1 reply
 * 2 participants
 * Last reply from: [dahousecat_net](https://wordpress.org/support/users/dahousecat_net/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/adding-conditionals-to-load-script/#post-1096691)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
