my website and plugins insert some jquery code between HTML tag and also whatever I do to insert jquery as a first script in the head section I can't get it to work

I tried

function use_jquery_from_google () {
    if (is_admin()) {

    global $wp_scripts;
    if (isset($wp_scripts->registered['jquery']->ver)) {
        $ver = $wp_scripts->registered['jquery']->ver;
    } else {
        $ver = '3.1.4';

    wp_register_script('jquery', "//ajax.googleapis.com/ajax/libs/jquery/$ver/jquery.min.js", false, $ver);

also putting


directly into header.php and index.php of theme but I got no success

so what can I do to make Jquery load really before everything because editing third party plugin is really frustrating and time-consuming


enter image description here enter image description here

1 Answer 1


The function wp_register_script has a parameter called $in_footer. Setting this to false will add the script to the head.

wp_register_script( string $handle, string|bool $src, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

In addition, if you deregister jquery, you can manually add the script in your head above wp_head(). This is generally not recommended.

  • Hello thanks when I add the script tag before wp_head() and load my main page there are like 15 more scripts before Jquery loading I think its because of plugins I want to load before them
    – zEn feeLo
    Commented May 2, 2019 at 23:25
  • there should be a way
    – zEn feeLo
    Commented May 2, 2019 at 23:32
  • Other scripts may be relying on jQuery which is why it's still showing up. That's the $deps part of wp_register_script(). The appropriate way to work with this is to dequeue the default on the front-end of the site and then enqueue your own version to make it appear in the wp_head() first. codex.wordpress.org/Function_Reference/wp_dequeue_script Commented May 3, 2019 at 1:26
  • 1
    That being said, it sounds like you have a malicious plugin that's not following best practices. I would reach out to the developers and find out why. Commented May 3, 2019 at 1:27
  • yes exactly, they say their version fixed this but it doesnt , anyway is there a way or piece of code to inject jquery before everything because when I view page source jquery is at the top over everything but when DOM loads it goes down and other script shows first, Im looking for a fix to override this
    – zEn feeLo
    Commented May 3, 2019 at 8:55

Your Answer

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

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