<?php
//Load Javascript
function my_scripts() {
wp_register_script('fancyfields', get_template_directory_uri() . '/js/fancyfields-1.2.min.js', array('jquery'), null, true);
wp_register_script('headmap', get_template_directory_uri() . '/js/headmap.js', array('markerclusterer'), null, true);
wp_register_script('infobox', get_template_directory_uri() . '/js/infobox.js', array('markerclusterer'), null, true);
wp_register_script('gmaps_google', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://maps.google.com/maps/api/js?sensor=false", false, null, true);
wp_register_script('markerclusterer', get_template_directory_uri() . '/js/markclusterer.js', array('gmaps_google'), null, true);
wp_enqueue_script('fancyfields');
wp_enqueue_script('headmap');
wp_enqueue_script('infobox');
wp_enqueue_script('gmaps_google');
wp_enqueue_script('markerclusterer');
}
add_action('wp_enqueue_scripts', 'my_scripts');
?>
am i missing something here?
Why is this not working. I have placed the above code into the childs function.php file, but they scripts are not loading on the pages I need.
Can someone see a serious flaw here?
thanks!!
You said this is in a child theme so I'm presuming that's where the files are located as well.
get_template_directory_uri()
will return the parent theme. The files can't be found there so they aren't loaded.
Use get_stylesheet_directory_uri()
instead.
Eg
wp_register_script('fancyfields', get_stylesheet_directory_uri() . '/js/fancyfields-1.2.min.js', array('jquery'), null, true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.