1

So, the goal is to use jQuery Validation for a custom form. Maybe I'm going about this the hard way. But, here's what I'm doing:

  1. Uploaded the jQuery Validation file to my theme folder
  2. Created plug-in folder in plug-in's file
  3. Added php file with this code:

    function custom_validation() {
    
    wp_enqueue_script('jquery');
    
    wp_register_script( 'jq-validation', get_template_directory_uri() . '/jquery.validation/jquery.validation.js', array('jquery'),'1',false );
    
    wp_enqueue_script( 'jq-validation' );
    
    }
    
    add_action( 'wp_enqueue_scripts', 'custom_validation' );
    

And, it's not working. I'm trying to avoid adding:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>

To the header file. But, it works whenever I do that.

Any help is appreciated.

  • Are you getting any errors ? – bravokeyl Apr 24 '16 at 8:13
  • Where did you add the above code? – bravokeyl Apr 24 '16 at 8:16
  • Getting this error: chrismisterek.website/:592 Uncaught TypeError: $ is not a function Added maybe an hour ago – simplesimon Apr 24 '16 at 8:27
  • Is that error from custom script you have added ? – bravokeyl Apr 24 '16 at 8:37
2

WP loads jQuery in no conflict mode so shortcut $ is not available for jQuery to use .You should not use the $ variable for jQuery within WordPress.

jQuery(function ($) {
   //code here
})

or

(function($){

    //code here

})(jQuery);

There are so many Q&A which refers to the same conflict issue.Check this and this.

  • Thanks didn't realize my issue was in the script itself – simplesimon Apr 24 '16 at 8:39

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.