Jump to content
Nico Knoll

Release: TextformatterMarkExternalLinks

Recommended Posts

Hey,

the TextformatterMarkExternalLinks.module changes every <a href="..."> that contains an external link to <a href="..." class="external" rel="nofollow">. That's all. But if you want to add a css class for external links it's really useful.

Download: https://github.com/NicoKnoll/TextformatterMarkExternalLinks

Greets,

Nico

Share this post


Link to post
Share on other sites

Good idea, thanks for sharing Nico. 

Not sure what the nofollow would do to your sites rank... :)

I would also consider doing this as a simple hook on all/notall pages render.

Have just looked a moment into code. Not sure, but wouldn't it remove existing classe ar attributes?

Share this post


Link to post
Share on other sites

Nice job Nico! It looks well put together.

A couple questions:

1. What about an option of adding a target="_blank" attribute for external links? Honestly, that's the one my clients ask for more than any other. :)

2. Regex question just for fun: why are you using the 'U' (ungreedy) modifier in your regex? After a brief look, I couldn't identify that it would affect this particular regex, but not positive, so figured I'd ask.

Not sure what the nofollow would do to your sites rank...

I think it's just for external links, as a way to tell Google not to pass along pagerank to those links. But it's intended to be for things like user posted URLs in comments, rather than for regular external links. I would be curious to know if Google penalizes one for using rel="nofollow" for all external links across the board. I'm betting not, but it does seem like maybe an abuse of what the nofollow tag was intended for. :)

I would also consider doing this as a simple hook on all/notall pages render.

Then I would be really worried about the above, as that would apply it to all external links even if you had hard coded them in the template file. Keeping it as a textformatter at least ensures that it's only applied to the fields where you want it. Though I think it'd be even better if it was an option on our TinyMCE link screen, then it would be much more surgical and placed where you really want it.

Have just looked a moment into code. Not sure, but wouldn't it remove existing classe ar attributes?

It doesn't look to me like it would remove existing classes or attributes. But it does look like it would add second class or rel attribute to links that already had them. Maybe not an issue in TinyMCE since these attributes are disabled by default, but maybe a good thing to check for in a future version.

Last item I wanted to mention that applies to all modules. When you all make a module, put your name at the top, not mine. :) Here is the top of TextformatterMarkExternalLinks.module:

/**
* ProcessWire Mark External Links
* 
* ProcessWire 2.x 
* Copyright (C) 2010 by Ryan Cramer 
* Licensed under GNU/GPL v2, see LICENSE.TXT
* 
* http://www.processwire.com
* http://www.ryancramer.com
*
*/

So others looking at this would think I'm taking credit for your module. :) And I'll be glad to do that. But you deserve the credit. So something like this would probably be better:

/**
* Mark External Links module for ProcessWire 2.1+
*
* Add's a class='external' and a rel='nofollow' to every external link.
*  
* Copyright 2011 by Nico Knoll 
* http://p.stadtpirat.net/
* Licensed under GNU/GPL v2, see http://processwire.com/about/license/
*
*/

Or if you prefer to keep the ProcessWire copyright info, then just put it after yours:  

/**
* ProcessWire Mark External Links
*
* Add's a class='external' and a rel='nofollow' to every external link.
*  
* Copyright 2011 by Nico Knoll 
* http://p.stadtpirat.net/
* Licensed under GNU/GPL v2, see http://processwire.com/about/license/
*
* ProcessWire 2.x 
* Copyright (C) 2010 by Ryan Cramer 
* Licensed under GNU/GPL v2, see LICENSE.TXT
* http://processwire.com
* 
*/

Share this post


Link to post
Share on other sites

The point is I wrote this plugin for my schools site and thought maybe anybody else would may need this too :) But I will improve the double class thing in the next version. And maybe I add an option page for the "nofollow" attribute so you can disable this.

Greets,

Nico

Share this post


Link to post
Share on other sites

Hello,

I have a newbie question here:

I have installed the module. What would the next steps be to see how it works?

Do I have to activate it somewhere?

(I'm on PW 2.7)

Share this post


Link to post
Share on other sites

Hello,

I have a newbie question here:

I have installed the module. What would the next steps be to see how it works?

Do I have to activate it somewhere?

(I'm on PW 2.7)

Any module that is a textformatter needs to be applied to each of the required fields via the Text Formatters dropdown on the Details tab of the field's config.

Share this post


Link to post
Share on other sites

Compatibility note: This module should not be used with PW3 - PW now has it's own techniques to archive the desired effect.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...