Please help,
how can I add the following jquery script in the functions.php of enfold child theme?
$(document).on(‘click’, ‘li.whr-item a’, function(e) {
e.preventDefault();
window.open(this.href, ‘_blank’);
});
thanks in advance
i can not proove your function but embedding it in child-theme you can do it this way:
function your_custom_script(){
?>
<script>
(function($){
$(document).on('click', 'li.whr-item a', function(e) {
e.preventDefault();
window.open(this.href, '_blank');
});
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'your_custom_script');
you can give any name to your custom function – but it has to be identical with the name in the add_action section
use underscore as separation for words
by the way if that script does not work in that manner you like.
You can add to all li.whr-item a the attribute in that manner:
function your_custom_script(){
?>
<script>
(function($){
$(window).load(function(){
$('li.whr-item a').attr('target','_blank');
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'your_custom_script');
PS: the wonderful documentation is always worth a look.
https://kriesi.at/documentation/enfold/add-custom-js-or-php-script/
Great! Thank you.
Hi spapax,
Glad you got it working for you! :)
If you need further assistance please let us know.
Best regards,
Victoria