Title: Enqueue script in a page template
Last modified: August 30, 2016

---

# Enqueue script in a page template

 *  [Flourt](https://wordpress.org/support/users/flourt/)
 * (@flourt)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/enqueue-script-in-a-page-template/)
 * Hi everyone,
 * I want to enqueue a script I’ve made to display Google Maps. I use a template
   named **tco-gmaps.php** i don’t understand why it doesn’t working…
 * _Note : if I use is\_page(id) it’s working well but I don’t want to modify my
   functions.php each time I had page with this template._
 * Can you help me please ?
 *     ```
       /**
        * Enqueue my-theme scripts
        */
       function my_theme_enqueue_scripts() {
       	wp_enqueue_style( 'my-theme-styles', get_stylesheet_uri(), array(), '1.0' );
       	wp_enqueue_script( 'jquery' );
       	wp_enqueue_script( 'modernizer-scripts', get_template_directory_uri() . '/js/modernizr.js', array(), '1.0', true );
       	wp_enqueue_script( 'my-theme-scripts', get_template_directory_uri() . '/js/script.js', array('jquery'), '1.0', true );
   
       	if ( is_page_template( 'tco-gmaps.php' ) ) {
       		wp_enqueue_script( 'google-api-gmaps-scripts', 'https://maps.googleapis.com/maps/api/js?language=fr', array(), '1.0', true );
       		wp_enqueue_script( 'gmaps-scripts', get_template_directory_uri() . '/js/gmaps.js', array(), '1.0', true );
       		wp_localize_script( 'gmaps-scripts', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
       	}
   
       }
       add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_scripts' );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * (@mrtom414)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/enqueue-script-in-a-page-template/#post-6352995)
 * if your template is located in a subdirectory you need to include the path in
   your conditional statement
 *  Thread Starter [Flourt](https://wordpress.org/support/users/flourt/)
 * (@flourt)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/enqueue-script-in-a-page-template/#post-6353002)
 * I don’t have path subdirectory…
 *  [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * (@mrtom414)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/enqueue-script-in-a-page-template/#post-6353007)
 * ok I didn’t see anything wrong with the code. I thought it might be a path issue.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Enqueue script in a page template’ is closed to new replies.

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/enqueue-script-in-a-page-template/#post-6353007)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
