N Peter
asked on
Load google maps api into wordpress
Hi,
I would like to load this directly into wordpress without using echo in the header.
This is the code I used originally. Function only runs on a certain page and it is working.
This is the one I would like to use instead but unfortunately map is not loading.
Thanks
I would like to load this directly into wordpress without using echo in the header.
This is the code I used originally. Function only runs on a certain page and it is working.
function loadComplexMap() {
if (is_page(10)) {
echo "<script src='http://maps.googleapis.com/maps/api/js?key=mykeycomeshere'></script>\n";
echo "<script src='".get_template_directory_uri()."/lib/complexmap.js'></script>\n";
}
}
This is the one I would like to use instead but unfortunately map is not loading.
function loadComplexMap() {
function complexaddmap() {
wp_register_script( 'google-map-api', '//maps.googleapis.com/maps/api/js?key=mykeycomeshere', true);
wp_register_script( 'complex-map', get_template_directory_uri() . '/lib/complexmap.js', true);
wp_enqueue_script('google-map-api');
wp_enqueue_script('complex-map');
}
if (is_page(10)) {
add_action('wp_enqueue_scripts', 'complexaddmap');
}
}
Any ideas would be usefulThanks
ASKER
Hi Ray,
Thank you for your suggestion but I would prefer to use my own code rather than a plug-in.
Thank you for your suggestion but I would prefer to use my own code rather than a plug-in.
OK, then I'll sign off. Good luck with your project.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://wordpress.org/plugins/wp-google-maps/