вызовите JavaScript из functions.php - PullRequest
0 голосов
/ 30 мая 2019

У меня есть JavaScript, который выглядит примерно так:

jQuery("ul[data-attribute_name=attribute_pa_afhentning-og-levering] li").click(function(){
    var selectedlevering = jQuery("ul[data-attribute_name=attribute_pa_afhentning-og-levering]").find("li.selected").attr("data-value");
    if (selectedlevering == "afhentning"){
        jQuery("ul[data-attribute_name=attribute_pa_packages] li[data-value=afhentning] span").click();
        jQuery("ul[data-attribute_name=attribute_pa_packages] li[data-value=afhentning]").hide(); // hide the "afhentning" option in "Packages" if you like
    }
});

Мне нужно вызвать этот скрипт из моего functions.php в Wordpress.Но как я это делаю?

С уважением

1 Ответ

1 голос
/ 30 мая 2019

Вы можете добавить собственный скрипт в раздел head, добавив wp_head как необходимое действие.

//----------------------------------------------------------------------
// Custom script in head section, add these lines in your functions.php
//----------------------------------------------------------------------

function custom_script_name(){
?>
<script>
// Your script here
</script>
<?php
}
add_action('wp_head', 'custom_script_name');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...