WordPress 101: How to Make Links in WordPress Open in a New Window
Sometimes you want a link to automatically open in a new tab or window. To make this happen, you need to add the code
target="_blank" to your link. To make this happen in WordPress without needing to write any code at all, you simply:
- Click the Link button (looks like a chain link in the Visual editor, the word “link” underlined in the Text editor)
- You’ll see a screen similar to the one shown in Figure 1 below.
- Tick the “Open link in a new window/tab” checkbox. Be sure to also add the link’s URL to the URL field.
- You’re all set.
Manually Set the Code
Want to do it yourself? In the Text editor, find your link. It’ll look something like this:
<a href="http://google.com">A link to Google</a>.
Add the following. This will work with any link:
<a href="http://google.com" target="_blank">A link to Google</a>.
Think About Why You Want to Do This Though
In general, the web development community thinks you should always leave opening links in new windows up to the user. Any user can hold in CTRL (in Windows) or COMMAND (on a Mac) while clicking a link to open it in a new window.
Chris Coyier over at CSS Tricks has a great article on when to use it, why you would use it, etc.
Personally, I think the consensus is a bit strict. I open links in new windows every time I link to an outside side (like I just did above). That’s my personal preference as a publisher and user. Read through his thoughts though, if you’d like to get into the ethics and theory of the whole thing.
If not, the code and tutorial above should do you right!
More WordPress 101 from ClickNathan.com
Up Next: Removing Woocommerce Scripts and CSS from Irrelevant Pages