I am in the process of learning WordPress/web development and have reached yet another hurdle. I cannot seem to load jquery as a dependency for a script. As I understand, jquery is already included with wordpress, but I cannot seem to get scripts to work, with errors in the browser console such as: Uncaught reference error: jquery is not defined at... . I would appreciate any guidance and I was hoping someone could explain the correct process of enqueueing or registering (still unaware of difference between the two) jquery, and correct me as to what i am doing wrong. I am new to programming in general and any advice would be a huge help.

The code I have so far is as follows:

//make a function to load scripts

function palpa_script_enqueue(){
    wp_enqueue_script('materializeJS', get_template_directory_uri() . '/inc/js/bin/materialize.js', array('jquery'), null, true );
    wp_enqueue_script('palpaJS', get_template_directory_uri() . '/inc/js/palpa.js', array('jquery'), null, true );
add_action( 'wp_enqueue_scripts', 'palpa_script_enqueue');

//code in palpa.js which requires jquery


//error in browser console enter image description here

//sources directory enter image description here



| improve this answer | |
  • Wonderful, that solved the issue, I completely missed that. Thank you so much for the help. I will remember to look out for the case in future. – Sameer Ali Jul 3 '17 at 10:45
  • Would appreciate any other tips regarding the code above if anything seems out of place? regarding using "jQuery" instead of the "$" sign do i have to replace it in each instance? – Sameer Ali Jul 3 '17 at 10:49
  • 2
    You can use it like this: (function( $ ){ /*here you can use '$' sign*/ })( jQuery ); – Sebastian Kaczmarek Jul 3 '17 at 11:08
  • Ah I see, This makes complete sense now. Thank you again very much for your kind help! – Sameer Ali Jul 3 '17 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.