Advertisements
Connect with us

Tips & Tricks

How to: Open external links in a new window

Over the weekend, I attended WordCamp Denver, and I was asked by John Hawkins how to force links to open in a new tab with out editing the source code. So, today lets learn a simple jQuery trick to open all external links in your site in a new tab or window. We are going to make sure you have jQuery active on your site, you can do this easily in WordPress, since it’s bundled with the latest installations. Use this code in your header: <?php wp_enqueue_script('jquery'); ?> then, below the wp_head add the following:

<script type="text/javacript">
var $j = jQuery.noConflict();

$j(document).ready(function() {
//external attribute
    $j("a:not([@href*=http://YOURSITE.com/])").not("[href^=#]")
        .addClass("external")
        .attr({ target: "_blank" });
    }
);
</script>

That’s it, just make sure you change the http://YOURSITE.com to your website.

Update

If you like you can remove the var $j = and replace all $j with simply just $

 

Advertisements

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

Harold Lederman Net Worth: How Rich Was Boxing Legend Actually?

Harold Lederman Net Worth: How Rich Was Boxing Legend Actually?

Harold Lederman was a boxing judge and analyst. He was in boxing for around 5 decades. Harold Lederman net worth before his death is estimated to be $3 million. Lederman was born on January 26, 1940, in The Bronx, New York. He went to Columbia University and after graduation earned a license from New York’s […]

Pua Magasiva Net Worth: How Rich was Pua Magasiva Actually?

Pua Magasiva Net Worth: How Rich was Pua Magasiva Actually?

Pua Magasiva was a New Zealand actor best known for his role as Shane Clarke, the Red Ranger from Power Rangers Ninja Storm. Pua Magasiva net worth before his death is estimated to be $600,000. Magasiva was born on August 10, 1980, in Apia, Samoa but was raised in Wellington, New Zealand since he was […]

MindofRez Net Worth: 5 Interesting Facts You Should Know

MindofRez Net Worth: 5 Interesting Facts You Should Know

Bryan Carti is a Youtuber who is well known for his channel called “MindofRez” which he started on June 8, 2016. Here are some interesting facts about MindofRez: 1. MindofRez has an estimated net worth of $2 million As of 2019, MindofRez net worth is estimated to be around $2 million. MindofRez has been able […]