Last active
May 14, 2016 17:40
-
-
Save sjaved87/e5f06cb3320ab76126ee232b8c94e092 to your computer and use it in GitHub Desktop.
WordPress open all external links in new window.
This file contains hidden or 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 | |
| function sjaved_open_external_links_in_new_window(){ ?> | |
| <script type="text/javascript"> | |
| jQuery(document).ready(function($){ | |
| $('a').each(function() { | |
| var a = new RegExp('/' + window.location.host + '/'); | |
| if(!a.test(this.href)) { | |
| $(this).click(function(event) { | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| window.open(this.href, '_blank'); | |
| }); | |
| } | |
| }); | |
| }); | |
| </script> | |
| <?php } | |
| add_action('wp_footer', 'sjaved_open_external_links_in_new_window', 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment