How to Open External Links in New Window in WordPress

Posted on 7th Jun, 2011 in jQuery Snippets


Here is very simple way to open external URL links in new window or tab in WordPress using the jQuery library. Just copy & paste the following code somewhere between your head tags.


<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("body a[href^='http://']").not("body [href*='thechoppr.com']").attr('target','_blank');
    });
</script>

This link will open in new window & this will not.