Tagged: masonry
I have added the code in the child functions.php file (as suggested here: https://kriesi.at/support/topic/how-to-masonry-items-open-in-a-new-window/?login_error) but portfolio items won’t open in a new window from the Masonry Grid. Do I need to do anything else or is that all – add the below code in functions.php?
Code: 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’);
Hi ElizabethEnglish,
The code provided will only open masonry links in new tab if they are external link.
To change it’s behavior to include all links, please change it to:
function masonry_links () {
?>
<script>
window.addEventListener('DOMContentLoaded', function() {
(function ($) {
$(document).ready (function () {
var url = new RegExp(location.host);
$('.av-masonry-entry').each(function () {
$(this).attr('target', '_blank');
});
});
}) (jQuery);
});
</script>
<?php
}
add_action ('wp_footer', 'masonry_links');
Hope it helps.
Best regards,
Nikko
That works! Thank you!
Hi ElizabethEnglish,
I’m glad that we could help you :)
Thanks for using Enfold and have a great day!
Best regards,
Nikko