Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know that wordpress ships with jquery. I have built my site first in html and every script that I have running in the html version works fine running version 1.4.2. I included this same jquery script and now one of my features don't work. This is how I am loading jquery into the head of my site

function register_savior_scripts(){
    wp_deregister_script('jquery');
    wp_enqueue_script('prettyPhoto', get_template_directory_uri().'/js/jquery.prettyPhoto.js', array('jquery'));
    wp_enqueue_script('js-scripts',get_template_directory_uri().'/js/jquery.js');
    wp_enqueue_script('slider', get_template_directory_uri().'/js/coin-slider.min.js', array('jquery'));
}
add_action('wp_head','register_savior_scripts', 0);

If I check the head, I see the script. It looks like this

<script type='text/javascript' src='full path removed/js/jquery.js?ver=3.4.1'></script>

It's not version 3.4.1. Not sure that matters. The script that it is running I put directly into the head and is this code

<script>
$(document).ready(function(){
        $(".controls").click(function(e){
            if($(this).hasClass('down-arrow')) {
                $(this).addClass('up-arrow').removeClass('down-arrow');
            }
            else {
                $(this).addClass('down-arrow').removeClass('up-arrow');
            }
            e.preventDefault();
            $("#logo-background").slideToggle("slow");
        });
});

Is there a better way to load the script above into the head? Do you know why it would work on the html but not wordpress?

All it does is slide a div up or down to hide it if you press a link.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

you're deregistering jquery, then registering it under the handle js-scripts, but then specifying the jquery handle as a dependency for your other scripts. also, use the wp_enqueue_scripts hook for wp_enqueue_scripts function, not wp_head. the appended version doesn't matter, but you can pass null as version parameter to get rid of it completely if you want.

share|improve this answer
    
well, I made the changes you suggested. Those were good ideas. I found that the reason the code isn't working is because of other scripts I have loading in the head section of my site. This is weird because it works just fine on the html version. Why would the WordPress version be any different? –  Jamie Aug 16 '12 at 0:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.