Last active
March 10, 2022 16:33
-
-
Save lelandf/6ff9e9bf91066e09a5dbf6c0b3c8cbee to your computer and use it in GitHub Desktop.
Open /event/ links in new window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_footer', function() { | |
// Evaluate conditional here | |
// Maybe an is_page conditional? https://developer.wordpress.org/reference/functions/is_page/ | |
if ( true === true ) : | |
?> | |
<script> | |
(function () { | |
// CUSTOMIZE DOMAIN NAME HERE | |
const DOMAIN_NAME = 'www.example.com'; | |
// Grab all links that start with /event/ | |
const eventLinks = document.querySelectorAll( `a[href^="https://${DOMAIN_NAME}/event/"]` ); | |
// Apply the target="_blank" attribute/value to each link | |
eventLinks.forEach( link => link.setAttribute( 'target', '_blank' ) ); | |
} )(); | |
</script> | |
<?php | |
endif; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment