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 can't figure out why Jquery isn't working on my Wordpress site. Am I setting it up right? Any help or suggestions is appreciated! Thanks.

Here is what I have in my function.php

 function my_scripts_method() {
     wp_deregister_script( 'jquery' );
     wp_register_script( 'jquery', 'ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js');
 wp_enqueue_script( 'jquery' );
}    
     add_action('wp_enqueue_scripts', 'my_scripts_method');

and on my header.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
            <title> 
    <?php
        wp_title('-', true, 'right');
        bloginfo( 'name');
    ?>
    </title>
    <?php wp_head(); ?>
    <script type="text/javascript" src="js/script.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale = 1.0">
      <!--[if lt IE 9]!>
 <script src="dist/html5shiv.js"></script>
 <![endif]-->
</head>
share|improve this question
    
What happens when you use the correct jQuery version? I mean the one shipped with WordPress. It is not compatible with Google’s. –  toscho Jun 18 '13 at 8:06
    
Are you referring to: wp_enqueue_script('jquery'); It still wasn't working when I plugged this into function.php –  Waymond Jun 18 '13 at 8:11
    
What do you need in 1.10 that isn't in 1.8.3 (the version that comes with WordPress)? –  Andrew Bartel Jun 18 '13 at 22:04
    
@AndrewBartel I ended up plugging this in and it worked. pastebin.com/7WK6pcAf . I still don't understand why wp_enqueue_script( 'jquery' ); in functions.php didn't work. –  Waymond Jun 18 '13 at 22:36
    
Did just enqueueing your new js file not work..? You're treading into dangerous territory as far as code maintainability and future upgrades here. –  Andrew Bartel Jun 18 '13 at 23:24
show 2 more comments

4 Answers

You should also enqueue you other JavaScript files and be sure that your jQuery dependent scripts are loaded after jQuery is loaded.

wp_enqueue_script( 'jquery' ); // Will load jquery from WordPress built in jquery handle

wp_register_script(
    'theme-script',
    get_stylesheet_directory_uri() . '/js/script.js',
    array('jquery'), // dependencies
    '1', // your version number
    true // script in footer
);
wp_enqueue_script( 'theme-script' );*/
share|improve this answer
    
I plugged in your code as well as @vinod Dalvi in functions.php and got it working. I don't know if that's the correct way to do things but it works for now. Thank you, sir! –  Waymond Jun 18 '13 at 20:01
add comment

I don't think you have to register jquery. I just put this in my functions.php:

function my_scripts_method() {
wp_enqueue_script(
    'main',
    get_template_directory_uri() . '/js/main.js',
    array( 'jquery' )
);
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

It includes my custom scripts that are reliant on jquery.

share|improve this answer
    
I tried that too.Here is the link listentotheway.com/pics . That text should be blinking but if you look in dev tool, it's not finding myscript.js . –  Waymond Jun 18 '13 at 16:19
    
Your jquery is loading fine. Did you check the path to your script? Right now it is ` <script type="text/javascript" src="js/myscript.js"></script>` It should have your root directory at the beginning of the src. –  mantis Jun 18 '13 at 16:30
    
Yeah, it showing that it loads in in listentotheway.com/js/myscript.js. However, in the console, I'm getting a 404 in there. I just tried <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/myscript.js"></script> and getting an error. I guess I'm in a jquery problem now and am in the wrong forum unless you have suggestions, I'll take them lol. –  Waymond Jun 18 '13 at 17:53
    
I think it should be src="<?php echo get_template_directory_uri(); ?> –  mantis Jun 18 '13 at 19:19
add comment

Check the jquery url in your code it is without http:// protocol which is wrong, it should be with http:// so the correct code is as following :

function my_scripts_method() {
 wp_deregister_script( 'jquery' );
 wp_register_script( 'jquery','http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js');
 wp_enqueue_script( 'jquery' );
}    
 add_action('wp_enqueue_scripts', 'my_scripts_method');
share|improve this answer
    
Thank you for that. I changed it and it's still not working for some reason. I'll have to keep going at it until I figure it out. Appreciate it. –  Waymond Jun 18 '13 at 8:37
    
here is the link to my problem. The text should be blinking but isn't finding my myscript.js. Any help is appreciated! Thanks listentotheway.com/pics –  Waymond Jun 18 '13 at 16:22
add comment

Delete what you have in your functions.php. Install the Use Google Libraries plugin. Once activated, you will see that there are no settings or such. There is nothing to do. Just activate the plugin. The Javascript should work now. Quick tip: put it in the footer (before the </body> tag) for faster site loading.

Hope this helps!

share|improve this answer
    
I just did that, thanks. I'm looking in the console and it's not finding script.js. Here is what I have at the footer. I'm plugging it in correctly, yes? <?php wp_footer(); ?> <script type="text/javascript" src="js/script.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> </body> </html> –  Waymond Jun 18 '13 at 15:54
    
Delete the code: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>. Install the "Use Google Libraries" plugin instead. It should work. Also, just double checking, the script.js file has working javascript and is in the correct path? –  Shaan Singh Jun 22 '13 at 21:21
    
Thanks @Shaan , I got it to work. I appreciate it. –  Waymond Jun 22 '13 at 21:29
add comment

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.