Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1041169

    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

    #1041198

    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

    #1041200

    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/

    #1041309

    Great! Thank you.

    #1041391

    Hi spapax,

    Glad you got it working for you! :)

    If you need further assistance please let us know.

    Best regards,
    Victoria

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.