1

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

I tried

function use_jquery_from_google () {
    if (is_admin()) {
        return;
    }

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

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

also putting JQuery CND script tag

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>

almost everywhere including directly into header.php and index.php of the theme when I put the script tag before wp_head() and load the page there are still 15 more script tag before it and I think they are related to my plugins

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

UPDATE

enter image description here

enter image description here

zEn feeLo
  • 1,877
  • 4
  • 25
  • 45

1 Answers1

1

Cameron, you can use jQuery by enqueueing it in your header.php or functions.php file. Here are a few articles with the step by step:

https://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

or

How do you install jQuery in Wordpress?

Updated:

Try changing your <head> section of your header.php file to this:

<head>
<?php wp_enqueue_script("jquery"); ?>
<meta charset="<php bloginfo('charset'); ?>" />
<?php wp_head(); ?>
</head>
Iisrael
  • 397
  • 4
  • 17
  • as I said I did this , but the problem is one of my plugins put a jqeury dependent script file on top of everything – zEn feeLo May 02 '19 at 23:21
  • 1
    Cameron, I don't see this in the code you provided. Try putting this at the very top of your header.php: `` – Iisrael May 02 '19 at 23:28
  • before wp_head() ? – zEn feeLo May 02 '19 at 23:29
  • Cameron, yes, based on the article I linked – Iisrael May 02 '19 at 23:30
  • I did but still more script tags before it , I think my plugins put these scripts before everything, I want to override it – zEn feeLo May 02 '19 at 23:31
  • hmm, are you still deregistering the default jQuery script as noted in the code you provided? – Iisrael May 02 '19 at 23:35
  • no , I commented everything, Im updating my code, please check – zEn feeLo May 02 '19 at 23:39
  • if I put into header before wp_head() the result is still the same – zEn feeLo May 02 '19 at 23:45
  • Cameron, is the updated code I put in my answer how you had it set up? – Iisrael May 02 '19 at 23:50
  • you put it before meta tag ? should it make a difference ? I think you didnt get the problem , as I told you There are plugins which put more scripts before this one I doesnt matter where I put the code in the header. php I should do something my script tag load before them How do I override ? – zEn feeLo May 02 '19 at 23:53
  • Cameron, I am sorry I wasn't able to provide you with a solution that resolved the other scripts from loading. I was answering this "so what can I do to make Jquery load really before everything because editing third party plugins is really frustrating and time-consuming" – Iisrael May 03 '19 at 00:07