Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1124289

    Hi,

    I’ve looked at various solutions posted here in the forum and I haven’t been able get the masonry gallery images (which are pulled from portfolio) to open a new window.

    Either I’m doing it incorrectly or there must be a better way.

    I look forward to seeing a solution.

    • This topic was modified 5 years, 3 months ago by slui.
    #1124383

    Hey slui,

    Please add following code to Functions.php file in Appearance > Editor:

    
    function add_custom_target(){
    ?>
    <script>
    jQuery(window).load(function(){
    jQuery('.av-masonry-container a ').attr('target','_blank');
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_target');
    

    Best regards,
    Victoria

    #1124384

    Hey slui,

    Please add following code to Functions.php file in Appearance > Editor:

    
    function add_custom_target(){
    ?>
    <script>
    jQuery(window).load(function(){
    jQuery('.av-masonry-container a ').attr('target','_blank');
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_target');
    

    Best regards,
    Victoria

    #1124814

    Thanks Victoria…this worked perfectly. Please close ticket.

    sl

    #1124898

    Hi slui,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1193359

    Hi Victoria,

    This works when i add it to the functions.php however I was wondering if there is a way to have this apply to just one page?

    I want all the masonry grids on one specific page only to open in a new window. Is this possible?

    Thanks
    Alice

    #1193365

    you can either do it via page-id-xyz or via custom-class of your masonry

    function add_custom_target(){
    if(is_page(xyz)){
    ?>
    <script>
    (function($){
        $(window).load(function() {
          $('.av-masonry-container a').attr('target','_blank');
        });
    })(jQuery);
    </script>
    <?php
    }
    }
    add_action('wp_footer', 'add_custom_target');

    or as said before with custom-class on masonry element – f.e.: masonry-blank:

    function add_custom_target(){
    ?>
    <script>
    (function($){
        $(window).load(function() {
          $('.masonry-blank a').attr('target','_blank');
        });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_target');

    last version has the advantage that you can have more than one masonry on this page – the one with class opens links blank – the other not
    and if you have a masonry on a different page it will work too – if class is set.

    #1193367

    That worked perfectly! Thank you very much

    #1193395

    Hi,

    Thanks for helping out @guenni007.

    Best regards,
    Rikard

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