# Is there a trick to conditionally wp_enqueue_scripts?

**URL:** https://discourse.roots.io/t/is-there-a-trick-to-conditionally-wp-enqueue-scripts/1504
**Category:** archived 🗄
**Created:** 2014-04-04T05:13:23Z
**Posts:** 5
**Showing post:** 5 of 5

## Post 5 by @cfx — 2014-04-15T04:25:49Z

You need to comment out the original `roots_scripts` registration and move it into your conditional, then set `googlemaps` as a dependency because I suspect `googlemaps` gets loaded _after_ `roots_scripts` but you need it loaded before. In that same vein you need to remove the `roots_scripts` dependency from `googlemaps`: your dependencies should be the other way around.

Something like this works:

```
if (is_page('contact')) {

  //make sure jquery is the only $dependency here!
  wp_register_script('googlemaps', 'https://maps.googleapis.com/maps/api/js?sensor=false', array('jquery'), null, true);

  //this is the new bit with the Roots JS dependent on (i.e. after) Google Maps
  wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', array('googlemaps'), 'ed21e6ee0eccdda773ac70eab1eb81f6', true);

} else {
   wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', array(), 'e3fd68a6394fc4bd1983a92cdd98329f', true);
}
```

Then just do these as usual:

```
wp_enqueue_script('modernizr');
  wp_enqueue_script('jquery');
  wp_enqueue_script('maps'); //this is new!
  wp_enqueue_script('roots_scripts');
```

---

_[View the full topic](https://discourse.roots.io/t/is-there-a-trick-to-conditionally-wp-enqueue-scripts/1504)._
