1

Im having some trouble adding jquery libraries to a custom wordpress plugin. It's telling me it cant find variable jQuery. Any help is much appreciated.

simplepluginclass.php includes functions.php

include plugin_dir_path( __FILE__ ) . 'inc/functions.php';

functions.php

 <?php
        function register_jqscripts() {
            wp_enqueue_script('jQuery', 'http://code.google.com/apis/libraries/devguide.html#jquery');
            wp_enqueue_script('jquery-ui-core', 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js');
            wp_enqueue_script('jquery-ui-datepicker');
            wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
        }


    function add_datepicker(){ ?>
    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#dob').datepicker({
            dateFormat: 'dd-mm-yy'
        });
    });
    </script>
    <?php
    }
    add_action( 'register_form', 'register_jqscripts' );
    add_action('register_form','add_datepicker');

?>

simplepluginclass.php

 <label for="dob"><?php _e( 'Date of Birth', 'sportspress' ) ?><br />
               <input type="date" class="customdatepicker" id="dob" name="dob" />
          </label>
1
  • 1
    Who is "it" that is telling you something? Commented Feb 19, 2019 at 14:26

1 Answer 1

4

The link that you're referencing for jQuery is pointing to the Google Code documentation. Change the link to point to the jQuery source file on the CDN:

wp_enqueue_script('jQuery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
Sign up to request clarification or add additional context in comments.

2 Comments

thanks that was the jquery problem. sorry i totally missed that i was pointing to documentation. thanks.
for some reason the datepicker is not loading in safari but its working now in chrome. i guess it might be a cacheing issue.

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.