A
A
Alexander2016-06-06 13:30:07
JavaScript
Alexander, 2016-06-06 13:30:07

How to include the jQuery library from WordPress?

Good afternoon

Now I'm building a template from Bootstrap for WordPress and I came across the fact that the menu during adaptation works if a remote file is connected from a folder inside the template or on another server as written below:

function jquery_enqueue() { 
    wp_deregister_script('jquery');
    wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', false);  
    wp_enqueue_script('jquery'); 
}  
if (!is_admin()) add_action('wp_enqueue_scripts', 'jquery_enqueue', 11);


But with third-party links in the code, they will not be allowed into the wordpress.org directory!

But I found out that WordPress has a built-in jquery (or something like that, I didn’t fully understand this moment) But how to connect it and not a third-party file?

It feels like the answer is very close, but it eludes me.

How to include the jQuery library from WordPress?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Nikolaev, 2016-06-06
@Heian

You just don't need to re-register anything. Plus, it is usually enabled by default (but it depends on the theme).

function jquery_enqueue() { 
    wp_enqueue_script('jquery'); 
}  
add_action('wp_enqueue_scripts', 'jquery_enqueue', 10);

N
Ninja Mate, 2016-06-06
@victorzadorozhnyy

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

$deps = array()
write down the dependencies here
My example (sorry too lazy to redo it, but I hope it will be clear)
wp_enqueue_script('admin.bundle', plugins_url('/admin.bundle.js', __FILE__), array('jquery'), '1.12', true);
wp_localize_script('admin.bundle', 'Slug_API_Settings',
    array(
        'root' => esc_url_raw(rest_url()),
        'nonce' => wp_create_nonce('wp_rest'),
        'ajaxurl' => admin_url('admin-ajax.php'),
        'myajaxnonce' => wp_create_nonce('myajax-nonce')
    )
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question