Last active
August 15, 2020 07:23
-
-
Save wpscholar/4637176 to your computer and use it in GitHub Desktop.
Open all external links in a 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
/** | |
* Open all external links in a new window | |
*/ | |
jQuery(document).ready(function($) { | |
$('a') | |
.filter('[href^="http"], [href^="//"]') | |
.not('[href*="' + window.location.host + '"]') | |
.attr('rel', 'noopener noreferrer') | |
.attr('target', '_blank'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming I can add "nofollow" to the rel attribute as well. Could you give me an example script on how to add an exception, for when the A tag has class=trusted? Where only the target attribute is set and the rel attribute is left empty. Many thanks and happy new year!