0

I am trying to enqueue a js file in functions.php but its not working. Following is my code

 add_action('init','shopswing');
function shopswing(){

    if(!is_admin()){
        wp_register_script('swing',get_stylsheet_directory_uri(). '/js/swing.js',array('jquery'));  
        wp_enqueue_script('swing');
    }
}

and somehow, my site stop responding when i include the code of swing.js

jQuery(document).ready(function() {
        $("ul>li>img").mouseenter(function(){
        $(this).parents("ul")
        .find(".toolTip")
        .animate({ 'height':'200px'})
        //.css({"display":"block"});
    })
    .mouseout(function(){
        $(this).parents("ul")
        .find(".toolTip")
        .animate({ 'height':'0'})
        //.css({"display":"none"});
    });
});
0

Wordpress uses the noConflict version of jQuery which does not allow

$.

use

jQuery.

or simple replace

jQuery( document ).ready(function()

by

jQuery( document ).ready(function( $ )

hope that helps.

  • I tried but nothing, is my enqueue thing fine? i see that when i removed the script of enqueue from functions.php, the website was running – Nofel Nov 27 '13 at 11:42
0

found the problem! The problem was with the name of function, i am using woocommerce and i think the function name conflicted, changed it and it working!

  • That’s not really an explanation. – fuxia Nov 27 '13 at 12:26
  • you should use 'wp_enqueue_scripts' instead of 'init' to include js. – Manish Nov 27 '13 at 12:29

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