Add JQuery in Wordpress using HOOKS

1

I have a function that runs through a hook in wordpress, in which I install the JQuery

add_action('init', 'iniciarJQuery');
function iniciarJQuery() {
   if( !is_admin()){
   wp_deregister_script('jquery');
   wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"), false, '');
   wp_enqueue_script('jquery');
   }
}

how to know if you can compare if the JQuery is installed or not, to avoid duplicates and conflicts

I already know how to use als local versions, but you can compare if jQuery is installed on the page before I install it

    
asked by Ernesto Emmanuel Yah Lopez 18.07.2017 в 18:35
source

1 answer

0

To know if a script is in use you need the wp_script_is() function.

if ( ! is_admin() && ! wp_script_is( 'jquery', 'enqueued' ) ) {
    // jQuery no está cargado
}
    
answered by 20.07.2017 / 01:18
source