Is it possible to make some sort of change or add a plugin that allows me to make every ‘external’ link open in a new window?
Just an example: if my blog was called http//timmy.com/ and I wanted to link to http//tom.com/, it would open a new window instead of the same window,
but I wanted to link from http//timmy.com/ to http//timmy.com/somewhere/ in the same window.
So I want all external link from my website to another in a new window/tab,
but I want every internal link, from my website to somewhere else on my website, to be in the same window/tab.
Is this possible?
Yup can be done with javascript.
While you got answers on technical side how to do it, I want to chime in on usability side – you really shouldn’t.
Aside from some specific cases (non-web-based documents for example) opening new browser windows/tabs for links is considered very poor practice (and for very long time already).
While it might seems like a strategy to keep your site open in effect it is very likely to annoy users who didn’t explicitly want that new tab but got it anyway because you decided for them.
Well, no need to reinvent the wheel: External Links Plugin For WordPress, I can really recommend it.
Hi @ninjaboi21:
I see @curtismchale gave you a jQuery solution which should work fine. If you’d like a PHP solution, here’s one that should work for you too.
Basically the solution comes in two parts; first is to buffer the output using PHP’s
ob_start()
function, which is easy, and then to parse the output in the callback function, which is more involved. I used a not-so-elegant brute-force method; I’m sure there are better ways but the brute force method is what someone who’s not so bright like me uses. 🙂 Maybe someone else will come along with something more elegant.Here’s the code; put this in your theme’s
functions.php
file and you should be good to go:-Mike Schinkel