0

I am building a custom theme and using wp_enqueue_scripts to load a custom JS file for a specific page template. As you can see I declared jquery as a dependency...

function enqueue_theme_scripts() {
  if (is_page_template('template-contact.php')) {
    wp_enqueue_script(
      'template-contact-js',
      get_bloginfo('template_directory') . '/template-contact.js',
      array('jquery'),
      false,
      true
    );
  }
}
add_action('wp_enqueue_scripts', 'enqueue_theme_scripts');

This is what I have in the JS file...

(function($) {
  $(document).ready(function() {
    console.log($);
    console.log($.ajax);  
  });
})(jQuery);

This is what the 'console' tab shows...

Screenshot of Chrome Inspector console tab

jQuery is loaded, but the $.ajax method is not included.

This is what the 'sources' tab in the Inspector shows...

screenshot of jQuery 3.4.1 loaded in Chrome's inspector

As you can see it is loading jQuery version 3.4.1, but line 48 seems to indicate that ajax is being removed. How do I get jquery to load with the ajax method included?

2
  • 1
    jQuery 3.4.1 is not the version bundled with WordPress. Another plugin or your theme must have replaced it with its own version. Mar 1, 2020 at 2:17
  • @JacobPeattie You are correct. I found it. Post this as an answer, so I can give you points.
    – Kirkland
    Mar 1, 2020 at 4:44

0

Your Answer

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

Browse other questions tagged or ask your own question.