1

I am using this function in order to load jQuery and my custom script:

function.php

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');

    // Register and Enqueue a Script
    // get_stylesheet_directory_uri will look up child theme location
    wp_register_script( 'FormScript', get_stylesheet_directory_uri() . '/FormScript.js');
    wp_enqueue_script( 'FormScript' );
}

This is a snippet of my custom script:

if (typeof jQuery == 'undefined') {  
    // jQuery is not loaded
    alert("false");
} else {
    // jQuery is loaded
    alert("true");
}

$(document).ready(function() {

    $("#Main").hide();
    $("#Angehoerigkeit").hide();
    $("#Alter").hide();
    $("#Image").hide();

    ...
}

These div's are only located on one site in wordpress. The jQuery is loaded successfully but the div's aren't hiding. Any ideas? Thanks a lot.

1 Answer 1

2

Firstly, you shouldn't be deregistering jQuery, or loading it, you should just add is a dependency for your script, and Wordpress will take care of the rest

if (!is_admin()) {
    add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
}

function my_jquery_enqueue() {
    wp_register_script( 'FormScript', get_stylesheet_directory_uri() . '/FormScript.js', array('jquery'));
    wp_enqueue_script( 'FormScript' );
}

secondly, jQuery runs in noConflict mode in Wordpress

jQuery(document).ready(function($) {

    $("#Main").hide();
    $("#Angehoerigkeit").hide();
    $("#Alter").hide();
    $("#Image").hide();

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.