How do I enqueue jQuery in my theme? (6 posts)

  1. j@revive
    Posted 5 years ago #

    Hope someone can shed some light on this for me. I am using jQuery in a few of my themes and I was advised by the excellent ebook Digging into WordPress to use the built-in wordpress jQuery library by adding this code ...
    <?php wp_enqueue_script('jquery'); ?>
    So I plonked that in my themes in the <head> but it has no effect. At the mo I have uploaded a copy of jQuery to my themes and am linking to that, which works just fine. But obviously better to use the wordpress version already loaded. Can anyone tell me what I need to do?

  2. stvwlf
    Posted 5 years ago #

    You did the correct thing. That line has to be inserted BEFORE the
    <?php wp_head(); ?> line. Usually it doesn't work because its been inserted after that line.

  3. j@revive
    Posted 5 years ago #

    Thanks for your reply stvwlf.
    I checked and my enqueue is before the wp_head. Actually I checked the source code and there IS a link to the wordpress jquery copy in the wp-includes folder, but for whatever reason that copy isn't cutting the mustard with my accordion menu script. I'm using the jquery-1.4.2.min.js version which I include in my theme and that makes it work fine, so I don't know what the difference is here. It should be the same. Tested on two sites and same result. Anyone else had this problem?

  4. stvwlf
    Posted 5 years ago #

    make sure you are using
    jQuery(document).ready(function($) {
    and not
    $(document).ready(function() {

    and, if that doesn't resolve it,
    make sure your accordion menu script works OK with jQuery 1.4.2 and does not require an earlier jQuery version. Some older scripts require earlier versions.

  5. j@revive
    Posted 5 years ago #

    hmmm... the plot thickens. Thanks again for your reply stvwlf. I made that change and still no effect. Then I took a copy of the jquery.js file in wp-includes/js/jquery/ and tested it on my local server with lightbox and it didn't work with that either. I am currently using jquery-1.4.2.min.js which works with those plugins. But when I substitute this file in wordpress it does not. I'm not a javascript person. Any clues anyone?

  6. iftomkins
    Posted 4 years ago #

    Same for me! I can't enqueue for the life of me. Maybe it has to do with Buddypress or Bbpress?

Topic Closed

This topic has been closed to new replies.

About this Topic