<< Back to Blog

Open A Link In A New Window or Tab From The URL Attribute

Today I was tasked with opening specific links in a new window/tab on a WordPress site with a pre-built theme. I needed to be able to accomplish this by only changing the URL attribute of the href. The change could not be made throughout the entire site. Without getting into details on the theme itself I needed a way to change the link behaviour without being able to add:

... target="_blank"


In the end it was as simple as putting the following into the the theme’s provided URL field for each item:

javascript: window.open('http://www.yourlinkhere.com');


As shown in the theme’s portfolio custom post type:


changing the url attribute


I was able to find this solution at Stack Over Flow here.