Answer the question
In order to leave comments, you need to log in
How to connect external js with https to wordpress?
I'm trying to connect js from the Yandex.maps API.
The wp docks say that external js needs to be added without a protocol, and the Yandex docks say that js will only be returned via https
. How to be?
add_action( 'wp_enqueue_scripts', 'ya_api_myscript' );
function ya_api_myscript() {
wp_enqueue_script( 'yamps', '//api-maps.yandex.ru/2.1/?load=package.full&lang=ru-RU', null, true );
}
Answer the question
In order to leave comments, you need to log in
Accordingly, Yandex will give it via https and wp so it will connect.
but in general, nothing prevents you from specifying specifically https: // wordpress will not swear at this
Here is an excerpt from the working draft. Everything works as it should.
public function js()
{
wp_deregister_script('jquery');
wp_register_script('yandex-map', 'https://api-maps.yandex.ru/2.1/?lang=ru_RU', [], null, true);
wp_register_script('theme-libraries', get_template_directory_uri().'/assets/js/libraries.js', [], $this->version(), true);
wp_register_script('theme-application', get_template_directory_uri().'/assets/js/application.js', ['theme-libraries', 'yandex-map'], $this->version(), true);
wp_enqueue_script('theme-application');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question