Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WP – How to add a script to a specific page Reply To: WP – How to add a script to a specific page

#182125
taxicss
Participant

@Senff Your code doesn’t seem to work but if I remove the conditional if(is_page_template…), it works. This is my final code

// add google maps
  function load_google_script() {
    wp_register_script( 'googleapi', "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false");
    wp_register_script( 'googlemaps', get_template_directory_uri() . '/js/googlemaps.js', array(), '1.0.0', true );

    if(is_page_template('single-branches.php')) {
        wp_enqueue_script( 'googleapi' );
        wp_enqueue_script( 'googlemaps' );
    }
  }
  add_action( 'wp_enqueue_scripts', 'load_google_script' );