• For some reason, my jQuery scripts only seem to load when I am logged into WordPress. Here is the page: http://www.mcfaddengavender.net/newmg/

    As you can see, the images are not “sliding” in. However, if I login and return to the homepage, things work fine. Here is the code I’m using to run jQuery in the Functions.php:

    //jQuery - Use Google CDN instead of WP jQuery
    function my_scripts_method() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery',     'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js');
        wp_enqueue_script( 'jquery' );
     }
    }
    
    add_action('init', 'my_scripts_method');
    ?>

    Any ideas on what would cause such a weird issue?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It seems to be working fine for me.

    Try also using wp_enqueue_scripts instead of init for your action.

    Thread Starter JeremyEnglert

    (@jeremyenglert)

    I restored from an old backup and everything seems to be working fine now.

    However, what is the difference between “init” and “wp_enqueue_scripts”? I’ve seen them both used and they both seem to work.

    And thank you for taking the time to take a look! I appreciate it.

    Hello Jeremy,

    There are two main differences between those two actions.

    1) init fires before wp_enqueue_scripts.
    2) wp_enqueue_scripts has more params which can check to see if a script is already loaded or if it has dependancies. Basically it handles scripts better that init.

    Using wp_enqueue_scripts is the correct way to do what you are doing. Here is a short article on this topic as well: http://wordpress.stackexchange.com/a/55928

    Glad to help.

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Jquery only works when logged in’ is closed to new replies.