• 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)
Viewing 3 replies - 1 through 3 (of 3 total)

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