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

  • Version 1.3 Filter priority has been upped to 999 to get around some issues with markup plugins… option added to do 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

I’ve spent a lot of time writing this code and supporting it. If you derive some benefit from this code, please consider showing your gratitute in a more tangible
way. Thanks!

I have received $0 this month for my coding efforts.

Donate with PayPalAmazon.com Wishlist


211 Responses to “Identify External Links”

  1. [...] Identify External Links [ Tempus Fugit | TxFx.net ] Save it in a file named identify-external-links.php . Make sure there are no spaces before the opening <?php or after the closing ?> . [...]

  2. [...] Identify External Links Identifies all exteral links and adds class=”extlink” and optionally, target=”_blank” to open the links in a new window. [...]

  3. You have a very minor bug on line 35:

            return $matches[0];
    

    should be:

        if (!empty($matches[0])) {
            return $matches[0];
        } else {
            return '';
        }
    

    To see why it might matter, turn on define('WP_DEBUG', true); in your wp-config.php

    Ciao!

  4. Tom Usher says:

    Hi,

    I was up all night trying to figure out how to get back into my site and then determine what caused the problem. Little by little, I managed to get things working. Finally, I narrowed it down to an issue with your plugin, which I had been using without a hitch for months.

    I don’t know what caused it, but when I attempted to use the one click update on a deactivated plugin called “Share This,” the system locked up waiting for the update to download. When I gave up waiting and left the page, I couldn’t get back in. That event may have corrupted your plugin somehow.

    When I activated all my plugins, I received # 500 error messages. I deactivated them all and reactivated one at a time checking my index page and single post pages too. Your plugin ended up causing blank pages to load.

    I’m no expert in reading plugin code, but if you want me to zip and email you your plugin to take a look at to see what might have happened to it, I will.

    I just thought this might help somehow head off some incompatibility issues.

    I did enjoy your plugin. The only thing I noticed about it I would bother changing concerns the icons looking bad upon changing resolution. I checked the icons on Wikipedia to see if that happens to them too. It doesn’t. You might want to check out the difference between what they’re doing and your icons.

    I’ll keep your plugin installed but deactivated so I’ll know when there’s an update to try again.

    Thanks. Sorry this was so long. I think it’s partly because I’m overly tired.

    God bless,

    Tom Usher

  5. Tom Usher says:

    Hello again.

    I wanted to give you an update and make a clarification so my earlier comment won’t leave other readers wondering.

    Wow, I was tired. I still am, but I wanted to let you know that I confused your plugin with the “Link Indication” plugin when I reactivated my plugins after the “Share This” one-click-upgrade crash.

    I had not had your plugin activated for months. I had left it installed in the non-activated group so I would not try it again without an update that wouldn’t cause the blank-pages problem.

    I hope that makes sense.

    Your plugin is a good concept, but “Link Indication” seems to be capable of doing the same and more without locking up my site.

    Thank you for your patience with me while I’m sleep deprived.

    Tom Usher

  6. Jack says:

    Just tried this plugin and it didn’t work… is there any instruction on how to debug this plugin?

  7. Merlyn says:

    Greetings:

    I just installed your great plug in to add the “target=_blank” feature automatically but I’m really confused because I don’t know what should I do to do so.

    Have a nice day and thanks,

    .: Merlyn :.
    amorysexualidad.com

  8. chuyono says:

    The game has become the people’s lives in a large part of the game in the park where, dofus kamas is a favorite for all of the game,acheter des kamas on dofusvault.com we will be very much on the dofus kamas, Come on, friends, to understand All your favorite,acheter des kamas you should feel some happiness.

  9. Upekshapriya says:

    It appears that an anchor tag containing single quote marks around the url rather than double quotes causes the plugin to ignore the link.

  10. Upekshapriya says:

    The problem is solved by changing line 50 to:

    ` $pattern = ‘/(.*?)/i’;`

  11. Upekshapriya says:

    I’ll try again:

    	$pattern = '/(.*?)/i';

Leave a Reply