I use the following script to call the maps JavaScript in the page-about.php
template. But its actually not working. The scripts are executed nowhere:
// Load maps scripts
function maps_scripts()
{
// If query if current Page is not wp-login-php or admin page
if ( is_page_template('page-about.php') ) {
wp_register_script('gmapsapi', 'http://maps.google.com/maps/api/js?sensor=false', array(), '1.0.0', true);
wp_enqueue_script('gmapsapi');
wp_register_script('gmaps', get_template_directory_uri() . '/js/gmaps.min.js', array(), '1.0.0', true);
wp_enqueue_script('gmaps');
wp_register_script('map', get_template_directory_uri() . '/js/map.js', array(), '1.0.0', true);
wp_enqueue_script('map');
}
}
add_action('init', 'maps_scripts');
I also tried with is_page()
but its not working. When I delete the if
statements the scripts are loaded on all pages.
wp_enqueue_scripts
instead ofinit
.