I am taking an html template that is fully functioning with the jquery and javascript in the footer and I am converting it into WordPress. I have done this a few times and I always have trouble with the jquery. I always want to deregister the included jquery and use my own scripts that are up and running on my template. I feel like I am doing something wrong here because I have read that WordPress has jquery enabled by default; yet, when I add my scripts, the site crashes. so If I take this out of my footer

 <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.js"></script> 

and replace it with a call from function.php like so

 wp_enqueue_script( 'jquery');

it crashes.

The last snippet puts the jquery in the header. I found an option to add it to the footer on this site but it didn't work. is there a "Propper" way?

  • Are you including it in an action hook or just directly calling wp_enqueue_script? – Andrew Bartel Dec 9 '14 at 2:08
  • I am including it in the twentyfourteen_scripts which is being called on the wp_enqueue_scripts. So the add_action. – Jamie Dec 9 '14 at 2:28
  • could be because when you enqueue jQuery with wp_enqueue_script( 'jquery');, it loads jQuery files from wp-includes folder which runs in noconflict mode. But your custom jQuery rules are written for normal jQuery. – Robert hue Dec 9 '14 at 2:57
  • My first thought is you are loading two jQuery libraries. You may need to de-register the included jquery, and re-enqueue it in the way you want. Here is an example that uses CDN instead, but you can get the gist: css-tricks.com/snippets/wordpress/…. Also, you can pass a parameter to load it in the footer: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );. – jhoffmcd Dec 9 '14 at 6:55
  • 1
    @Jamie jQuery in WordPress runs in noconflict mode. And moving all your code to noconflict jQuery is not that hard, just need to add jQuery wrapper around it. – Robert hue Dec 10 '14 at 12:09

Your Answer

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

Browse other questions tagged or ask your own question.