Javascript files not being loaded
-
Hi all,
I am trying to load my JavaScript files in the footer of my page but having difficulty doing so.
I have the following function in my functions.php file but JQuery always gets loaded in the header even though I’ve set the in_footer flag to true.
function load_jquery() { if (!is_admin()) { wp_deregister_script('jquery'); // load the Google API copy in the footer wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', array(), '1.5.1', true); wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', array(), '1.5.1', true); } } add_action('init', 'load_jquery');
I have another function to load a plug in, this one does not get loaded at all;
function load_myscript() { if ( !is_admin() ) { // instruction to only load if it is not the admin area // register your script location, dependencies and version wp_register_script('myscript', get_bloginfo('template_directory') . '/js/myscript.js'); // enqueue the script wp_enqueue_script('myscript', get_bloginfo('template_directory') . '/js/myscript.js', array(), false, true); } add_action('init', 'load_myscript'); }
I’ve spent a lot of time trying to figure this out, I have the wp_footer() and wp_head() calls in the right places. I’ve read up on wp_register_script and wp_enqueue_script but did not find anything to help.
Sincerely appreciate any help.
Sid.
- The topic ‘Javascript files not being loaded’ is closed to new replies.