Tagged: new window, Portfolio
-
AuthorPosts
-
August 3, 2019 at 2:03 am #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.
August 3, 2019 at 5:49 pm #1124383Hey 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,
VictoriaAugust 3, 2019 at 5:49 pm #1124384Hey 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,
VictoriaAugust 5, 2019 at 6:43 pm #1124814Thanks Victoria…this worked perfectly. Please close ticket.
sl
August 5, 2019 at 9:09 pm #1124898Hi slui,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
VictoriaMarch 16, 2020 at 1:15 am #1193359Hi 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
AliceMarch 16, 2020 at 3:07 am #1193365you 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.March 16, 2020 at 3:24 am #1193367That worked perfectly! Thank you very much
March 16, 2020 at 5:26 am #1193395 -
AuthorPosts
- You must be logged in to reply to this topic.