Mv27
Mv27

Reputation: 560

call javascript from functions.php

I have a javascript there is looking like this:

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
    }
});

I need to call that script from my functions.php in Wordpress. But how am I doing that?

Best regards

Upvotes: 0

Views: 240

Answers (1)

Manish Pushkar Jha
Manish Pushkar Jha

Reputation: 138

You can choose to add the custom script in the head section by adding the wp_head as the required action.

//----------------------------------------------------------------------
// 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');

Upvotes: 1

Related Questions