Identify External Links
About
This plugin will add a special CSS class to all links in your entries and in your comments that go to external sites (sites other than your site). For more complex external link identification needs, check out Link Indication.
Download
Instructions
Copy and paste the text. Save it in a file named identify-external-links.php. Make sure there are no spaces before the opening <?php or after the closing ?>. Activate it from within the WordPress admin interface. You can then use a.extlink { } in your CSS to style it.
You can also edit a setting in the top of the plugin to add target="_blank" to external links, so that they open in a new window (this is from popular demand… please note that this is an annoying thing to do to your readers.)
Versions
target="_blank" Version 1.2 Doesn’t apply extlink class if there is an image within the link Version 1.1 Works for subdomains now (thanks h0bbel!) Version 1.0 Initial release

the download link is dead.
Thanks. Works now!
parseof all: Thank You! Your «Identify External Links» plug-in works great. But one little thing: I can’t get it to «parse» (I hope that’s the right word) the links-list on the sidebar. Check out my site bureaublumenberg to see what I’m talking about … I looked in the phps of my theme and your plug-in — but my knowledge is far from good. I tried to find/create a filter (in your plug-in) around line #63:
... add_filter('the_content', 'wp_external_links', 2);but I have no idea what’s replacement should be. Maybe you’ll have an idea. Thanks in advance, Yoram...
I’m just wondering if there’s a filter to add to get it to add the external class to the “get_links_list” or any of the other link-displaying options. Thanks.
Cool! Easy to install even for a beginner like me. I’ve made it work in less than a couple of second. I recommend it to everyone. Thank you for this.
Great idea!
For those of us who know *nothing* about php:
Could you please show how to edit the php to get it to add target=”_blank” to external links?
Thanks
I’ve made a version with the target=”_blank” option available at http://andrefrancoislandry.ca/?p=13 for those who know little about PHP.
Thanks Andre
Is it possible to have the script accept several domains as “internal”, i.e. if you have the blog on DomainA, but have a redirect from DomainB (C, D, E…)?
Grendel,
Yep, I can modify it to do that. I’ll try and do it tonight.
When I use the quicktag, your external link identifier think that the more link is an external link instead of properly seeing that it is an internal link. Any suggestions on how to fix this?
Your plugin does not work with the plugin SmartLink, because you have set the priority of 2 for the filter. SmartLink works on priority 5, so your filter starts to early and does not find any “a href=”.
If you change the priority to a value greater than 5, all works fine. I have made the following change to your source, so now it works fine with SmartLink:
add_filter('the_content', 'wp_external_links', 10);add_filter('the_excerpt', 'wp_external_links', 10);
I fixed the “more” link problem which incorrectly parsed the “read the rest of this post” links as external.
My update is available here.
How does Your (great) Plugin works with tag generatet links like “get_links_list”ÂÂ?
Thanks a lot.
Robert,
get_links_listdoesn’t have a filter, so no. You could, however, use the plugin to filter anything that has a filter.Great plugin!
Any chance you (or anyone) could tell me how to get it to
a) add a title to the applicable links (e.g.
title="[external link]“)but furthermore (I figured out how to do that part myself, it’s this next part I don’t know how to do)
b) add this title to any title the link might already have?
e.g. I might put a link in my post as follows
blahand I’d like this plugin to modify it so it becomes:
blahHmm, that didn’t come out how I expected (or how it did in the live preview)…
That last part should be more like this:
e.g. I might put a link in my post as follows
a href="http://blah.com" title="blah!"and I’d like this plugin to modify it so it becomes:
a href="http://blah.com" title="blah! [external link] class=”extlink”Jaimie,
that would, unfortunately, fall outside of the realm of a quick fix.
Hi Mark - I have been playing with your very cool external link plug in. Is it possible to make it recognize http://www.domainx.domain.com as an internal link and http://www.domain.com as an external link?
I would be great to know what thisplug actually does.I installed it and saw nothing.The instructions are poorly written nad tell newbies nothing
I am not the author, but it seems pretty straight forward to me. From above:
This plugin will add a special CSS class to all links in your entries and in your comments that go to external sites (sites other than your site).
So when you view your live page any “a href” to a page that is outside of your blog will have a bit of code added (style=”extlink”) added to the url. (Do a view sourrce on the code of a rendered page to see what I mean.
So, until you do the next step of course you will not see anything, because you do not have the appropriate css in your style sheet yet.
Again, from above:
You can also edit the plugin to make it do other things like add target=”_blank” to external links or to add special things only to your internal links.
So add a new style to your stylesheet called “a.extlink” and style it how you like. If you don’t know how to style css, then I suggest checking out positioniseverything.net. And look! even in this comment you can see the plugin in action! see that little square box with the arrow in it letting you know that “positioniseverything.net” is an external link? That is what this plugin does.
good luck!
Oh, and one other Mark:
it seems like the external link loses its special styling when the link wraps to a second line (at least if you have an image assigned to it it loses the image). I imagine that this does not really have anything to do with your plugin, per se and more to do with css/html. any ideas for a fix?
Hello. I want to thank you for such a useful script. I’ve been using it since the first day I installed WordPress, and haven’t looked back since.
Unfortunately, though, I recently decided to use Markdown to make the posting process easier. It’s been a few days since I’ve been using it and have gotten very used to it. There’s one problem, though, your plugin won’t work now. I just realized this. I looked at the code and realized it looks at the written text before it gets translated by the markdown plugin. So now I have quite the dilemma: I love your plugin and want to keep using it, but I’ve already written quite a few medium-length posts that I’d hate to have to go into and alter all the link code. And I’d hate to have to write HTML links forever just to accomodate your plugin.
I’m more of a Perl kind of guy, and so it’d take me forever to write the correct string-search syntax to get your plugin to work with markdown. Are you considering making alterations to this code to make it play nice with markdown?
If there’s anything I can help with, let me know. I’m really interested in making these two plugins work well together, so I can have the ease of use of markdown and the efficiency of Identify External Links.
Thanks!
Nevermind! I hadn’t realized that every plugin can be assigned a priority. So I just altered your plugin to be applied after markdown does its thing. And that was that.
Thanks again for such a great plugin!
Heyrsmith,
Change the line that says
$host = $matches[2];toreturn $matches[2];(as the next line is the one that filters out the subdomain). Now the comparison will be done including the subdomain.Serge,
Just what I was going to suggest! What priority did you need to assign it, so that I can make that change in a future version for Markdown compat?
Hey thanks Mark - that works like a charm!
And the fix for my problem noted in post #42 was easy, although I decided not to implement it: just add /*white-space: nowrap;*/ to the css style in question and it forces the link to stay together on one line. This can make for some ugly pages, especially in a fully justified layout.
Thanks for the plugin work and the quick response; keep your eye on your mailbox for something off your Amazon wish list…
The Plugin is great, but it has some problems in my wordpress (1.5.2). If I use the “more-Tag”, I get an anchorlink in the post, which looks like this
“some text as teaser , more text”
With this anchor it gets problems, if there is an external link in the following text… dont know why…
Sorry.. html-tags obviously not accepted.
One more try: The plugin has a bug, if the post-text is build like this:
teaser-text more text more text
Maybe you can have a try…
Is there any way to get this plugin to work with the Scripturizer plugin? The links to the bible verses don’t show up with the class=”extlink” in them.
Edit the plugin so that the priority is a higher number. Try 99.
Thanks, it worked.
hi, a long time ago, i posted a problem with smartlink plugin… that time, the problems was solved, now it reappears
maybe latest version changes something? (I’m using 2.3)
i changed the priority to 10, even to 99999999, but is stills without working…
example: link
Did you change the priority on all the hooks? If doing that doesn’t help, I don’t have any clue what’s going on with that other plugin (and actually, I’m updating the plugin now to make the priority very high… it should be run as late as possible, in all situations.)
yes, changed all 3 filters…
Hi, I installed the identify external links plug in, and I am not sure what to do now. Can someone plese help me? I unzipped, moved the php file into the plugins folder and activated it. What else do i have to do?
You can then use
a.extlink { }in your CSS to style it.Which part of the CSS do i put it in or what is a normal way to style it? Sorry, I don’t know this stuff at all as you can probably tell
Any part of the CSS will do. You can style it however you like… I put a little arrow next to it. Look at my CSS to find out how (but use your own arrow image, of course).
Just to test that it is working:
a.extlink { color: pink; background: black; }I put that at the bottom of the editing style.css page, and it doesnt work. can you sign on aim possibly?
You did it correctly. You just don’t have any external links in your entries (except for one, but it is an image). The ESPN link you tried to make is missing
http://so it actually points to your own site. Fix that link and it’ll work.THANK YOU so much! I appreciate your help more than words right now. Really, it was so great that you replied to me so quickly!
Hello, I have downloaded and installed/activated your plugin on my site. I have added the CSS a.extlink { } code and the plugin seems to be recognising external links correctly and showing them as such. My one problem is that it will NOT open the external links in a new browser window.
I have:
1) Ensured that the setting at the top of the .php plugin file is set to true (”$txfx_iel_use_target_blank = true;”)
2) Ensured that the plugin file has been uploaded correctly (not so much of an issue as seems to otherwise work)
3) Cleared my browser’s cache (and tried several browsers on several platforms)
Still no luck!!
Have you any advice on what could be causing the new window not to open with this? It’s driving me nuts!
Hi,
Further to the problems I posted above, I seem to have your plugin working with the new-window option for the time being by changing the line
return ‘‘ . $matches[5] . ‘‘;
to
return ‘‘ . $matches[5] . ‘‘;
This isn’t ideal, hardcoding this into your plugin, but it’s working for now on my blog - seemingly without any side effects.
I look forward to your thoughts on how I could resolve my issues without such an inappropriate fix
(Note, for your information, when I have your non-altered plugin installed with the new-window option == true, the html output on my blog is
a
href=”anexternalsite” class=”extlink”>link
/a
- Sorry for the funny formatting here, I’m not sure how to paste code up as is…?)
Hey,
Yeap Version 1.3 will not open in a new window no matter what I do. Yes I set the option correctly and I even tried the “mini-hack” above.
Version 1.2 works fine though so staying with it.
Now I have a request…
And that is you can support all four url versions?
See this to see what I mean:
http://www.war59312.com/archives/2006/03/11/windows_live_messengers_goes_live/#comment-263
See how only the one version is support? Would be awsome if all four versions worked.
Thanks a lot,
Will
Hey,
Never mind Auto-hyperlink URLs plug-in fixes the problem:
http://www.coffee2code.com/archives/2004/07/08/plugin-auto-hyperlink-urls/
Take Care,
Will
Hi,
When I attempt to review the spam comments caught by my Akismet plugin, your plugin seems to be loading, and then timing out. I cannot view my entire list of spam entries… it fails with:
Fatal error: Maximum execution time of 30 seconds exceeded in/home/tatumweb/public_html/blog/wp-content/plugins/identify-external-links.php on line 57
Is there any way you can force the plugin to not evaluate anything coming out of wp-admin?
Excellent plugin, by the way.
Rich.
BlogRodent
Cool plugin - but I have one problem: I use the More-tag in most of my posts. And the “Read the rest of this entry”-link that this tag inserts on my front page is recognized as an external link. Can I do something about this myself?
Thanks.
CaBe,
I don’t see it applying the external links class to those links on your site…
Rich,
Crazy! The regex shouldn’t be taking THAT long. But yes, it can be disabled in the admin… you’d just have it return the text if
is_admin()returns true. I can have that in the next release.Well, that was because I had deactivated the plugin while trying to solve this issue …
Now, I have activated it again …
“Version 1.3 will not open in a new window no matter what I do”
Sounds great to me, but mine are still opening in a new window.
Is there some way I could get a version that stops links opening up in a new window?
You see, I started my WP blog with target=blank and after a year I’d like to switch.
If I can figure out how to do this without recoding all previous posts, that would be grand.
I imagine a number of people are in my position. Seems to me there’d be more people moving over if we could have a quick fix. Or even a choice like on bloglines where it asks what your preferences are.