1

I've been trying to load a javascript file and its not loading, looked up the docs but cant seem to figure out why it wont enqueue. Site is here : site

In the console im getting an error message for cookies, i have also disabled all plugins, recently switching the visual composer one back on but seems like jquery is not working even though i can load it fine.

Also im queueing like this right now:

function edealsdirect_scripts() {

  wp_register_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery', '', false ) );
  wp_enqueue_script( 'jquery-cookie' );

}

add_action( 'wp_enqueue_scripts', 'edealsdirect_scripts' );
1

3 Answers 3

1

You are registering a script and then enqueuing is as a style-sheet.

Try this (Left a snippet of how to add CSS so you can use it in future and can see the difference between them):

<?php
function mytheme_custom_scripts(){
    // Register and Enqueue a Stylesheet
   // wp_register_style( 'name-of-style', get_template_directory_uri() . '/css/custom-style.css');
    wp_enqueue_style( 'name-of-style' );

    // Register and Enqueue a Script
    // get_stylesheet_directory_uri will look up child theme location
    wp_register_script( 'jquery-cookie', get_stylesheet_directory_uri() . '/vendor/js/js.cookie.js', array('jquery'));
    wp_enqueue_script( 'jquery-cookie' );

}

add_action('wp_enqueue_scripts', 'mytheme_custom_scripts');
Sign up to request clarification or add additional context in comments.

4 Comments

tried this, still doesnt seem to find the file, added screen shot to original post for reference. also tried this way, still doesnt appear: developer.wordpress.org/reference/functions/wp_enqueue_script
The path to your file must be incorrect or your using the same name when enqueuing multiple scripts. Try and look in your source code and search for the JS file and see what path it's attempting to load it on (If it's there at all) if it's not there something is conflicting with it.
fixed now, thanks, it was the script name, im assuming wordpress is using it somewhere as i havnt added that name before to my own. greatly appreciate the help. still didnt resolve the error message im getting but i think thats a different question to be asked, thanks again.
Your welcome! And are you sure the scripts not already being loaded by another plugin? If your using Chrome go to developer tools -> sources and then look and see if it's already been loaded. If you still can't get it working post again and I will try my best to help :)
1

You are queueing style instead of script. Change wp_enqueue_style to wp_enqueue_script

Also, jquery-cookie has to be loaded after jquery. You have missing $deps argument in function call. See documentation

wp_register_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery-cookie' );

1 Comment

tried this as well, still doesnt load, see screen shot comment on original post. is there anything else that could block it? i have other scripts style sheets loading perfectly fine, just seems to be this one file.
0

Try this one:

function edealsdirect_scripts() {
  wp_enqueue_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery' ));
}

add_action( 'wp_enqueue_scripts', 'edealsdirect_scripts' );

Currently on your site you are not loading the script file. I have checked if that is the correct path to the cookie script and it is, http://edeals.nickritson.co.uk/wp-content/themes/dragoncove-saltrock/vendor/js/js.cookie.js.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.