Last active
April 24, 2019 10:11
-
-
Save evemilano/0a8a8a03d8f62808b8c2afec7c964a6e to your computer and use it in GitHub Desktop.
WordPress plugin to open all external file in _blank page
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 | |
/* | |
Plugin Name: EVE Target _blank + noopener | |
Plugin URI: https://www.evemilano.com/ | |
Version: 2.9 201904 | |
Description: This plugin put target blank to all external links | |
Author: Giovanni Sacheli | |
Author URI: https://www.evemilano.com/about-me/ | |
*/ | |
function eve_blankext() { | |
?> | |
<script type="text/javascript"> | |
(function($) { | |
jQuery( document ).ready(function() { | |
add_target_blank_to_external_links(); | |
}); | |
function add_target_blank_to_external_links(){ | |
$('a[href^="http://"], a[href^="https://"]').not('a[href*="'+location.hostname+'"]').attr({target: "_blank", rel: "noopener"}); | |
} | |
})(jQuery); | |
</script> | |
<?php | |
} | |
add_action('wp_footer', 'eve_blankext' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Guida: https://www.evemilano.com/link-esterni-target-blank/