Title: Why is my function not working?
Last modified: August 20, 2016

---

# Why is my function not working?

 *  [egr102](https://wordpress.org/support/users/egr102/)
 * (@egr102)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/is-my-function-right/)
 * I’m trying to load up two JS files to just my template file ‘contact.php’. The
   function below isn’t working (its located in my functions.php file):
 *     ```
       function google_map_script() {
       	   // register your script location, dependencies and version
       	   wp_register_script('maps_script',
       	   	   'http://maps.googleapis.com/maps/api/js?sensor=false',
       	       array('jquery')
       	       );
   
       	   wp_register_script('gmap_script',
       	       get_template_directory_uri() . '/js/gmap.js',
       	       array('jquery')
       	       );
   
       	   // enqueue the script
       	   wp_enqueue_script('maps_script', 'gmap_script');
       	}
   
       	if ( is_page_template( 'contact.php' ) ) add_action('init', 'google_map_script');
       ```
   
 * I’d appreciate any pointers or help at all 🙂

Viewing 1 replies (of 1 total)

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [14 years, 3 months ago](https://wordpress.org/support/topic/is-my-function-right/#post-2545706)
 * Try `add_action('wp_enqueue_scripts', 'my_scripts_method');` instead of `add_action('
   init' ...` and remove that wp_enqueue() that you already have.
 * [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)

Viewing 1 replies (of 1 total)

The topic ‘Why is my function not working?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/is-my-function-right/#post-2545706)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
