Tagged: custom link, masonry, new window
I’ve set portfolio items to “define custom link”. On the page where I display the portfolio items I use the Masonry grid. When clicking on the item in the Masonry grid on frontend it opens the link in the same window. Is there a code to let the link open in a new window/tab?
Thanks in advance.
Hi YboS_2022,
Please try to check the answer on this thread: https://kriesi.at/support/topic/open-portfolio-link-in-a-new-window/#post-1287483
I hope it helps.
Best regards,
Nikko
Thanks for your help, but it doesn’t work.
I’ve put the code in the function.php file of the child theme. But the links are still opening in the same tab.
Hi,
Thanks for the link to your page, I see that you are getting this error (index):279 Uncaught ReferenceError: jQuery is not defined
Please try this code instead at the end of your child theme functions.php file in Appearance ▸ Editor:
function masonry_links () {
?>
<script>
window.addEventListener('DOMContentLoaded', function() {
(function ($) {
$(document).ready (function () {
var url = new RegExp(location.host);
$('.av-masonry-entry').each(function () {
if( ! url.test($(this).attr('href')) ) {
$(this).attr('target', '_blank');
}
});
});
}) (jQuery);
});
</script>
<?php
}
add_action ('wp_footer', 'masonry_links');
If this doesn’t help, please include an admin login in the private content area so we can be of more assistance.
Best regards,
Mike
Yes! Thank you very much. This code is working!
Issue solved.
Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.
Best regards,
Mike