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.

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

1 Answer 1

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.

1
  • Thanks didn't realize my issue was in the script itself Commented Apr 24, 2016 at 8:39

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.