Jump to content
formmailer

Add rel="nofollow" when adding a TinyMCE link

Recommended Posts

Hi,

Since I use sponsored (affiliate) links on my sites, I have quite a few links that need to have the rel="nofollow" attribute added. This is for example required to avoid Google penalties.

It would be great if this could be added to the ProcessWire Edit Link Process, just to avoid going in to the HTML view to add this attribute. It could be done with a checkbox, just like the Open in new window field.

I started to modify the module myself, but then realised that it might be better not to edit the core modules of PW. :-)

I hope Ryan can add this simple addition to the next PW 2.1 release.

Kind regards,

Jasper

Share this post


Link to post
Share on other sites

I think that rel="nowllow" is something that is very rarely used in TinyMCE or in any page content (more common in comments and other user generated comment). Also rel="nowllow" is something that average content editor is not aware, so that would be only noise in the link editor.

That being said, I think that it should not be in core, but maybe an additional module? I am sure that Ryan can tell you which hooks you should look for and help you to right direction.

Share this post


Link to post
Share on other sites

I agree that this is probably too specific for the core. But you can achieve this pretty easily and automatically just by doing a str_replace before outputting the field. So I recommend adding something like this (below) somewhere in your template before that field is output. This will automatically add a rel='nofollow' attribute to any external links:

<?php
$page->body = str_replace(' href="http://', ' rel="nofollow" href="http://', $page->body); 

Share this post


Link to post
Share on other sites

Hi,

Thanks for your replies.

I didn't realise that rel="nofollow" was so specific, probably because I am so used to build websites containing a few affiliate/paid links. As I said, when you use paid links on your site the, the rel="nofollow" is a must.

Ryan, you're solution would work fine if all (external) links would be paid links, but this isn't true. There are also links that don't require the attribute.

Any other solutions are welcome... (if there isn't a good solution I'll continue to edit the link in the HTML view, which isn't a big thing, but a checkbox or something like this would be easier  :))

/Jasper

Share this post


Link to post
Share on other sites

The plan is to add an "advanced" section (default collapsed) in the TinyMCE link editor where you can specify things like class name, title, target and rel. I put it on my to-do list a little while ago because I've had several occasions where I needed to add a class attribute to a link, and don't like having to go in and do it in the HTML view (and don't like telling the client to do that). I figured if I added that, then it makes sense to provide options for other <a> tag attributes, so rel will definitely be one of them. This isn't officially on the roadmap because it's a small update that won't take more than a couple hours, and will get put in whenever there is time. So now that I know there are others with a similar need, it'll likely come sooner rather than later.

Share this post


Link to post
Share on other sites

Sound great, Ryan!

You and ProcessWire rock!!! :D

/Jasper

Share this post


Link to post
Share on other sites

Something new on this? Is this already implememented? A client also wants to change the title attribute (although I try to teach him that this has no effects) :-/

Share this post


Link to post
Share on other sites

Hi there,

I have the same issue with nofollow.

The attribute is important for SEO (http://support.google.com/webmasters/bin/answer.py?hl=en&answer=96569). I have no problem with the idea to switch to HTML mode in tinyMCE, but when i insert the attribute in HTML mode, tinyMCE just removes it when I save.

I don't want to rush you to implement additional attributes ;) but it would be helpfull if you know how I can remove this filter mechanism or modify it (preferably without touching the core, but I guess thats impossible atm).

I'll take a look to tinyMCE forums, maybe i can find something there :)

Share this post


Link to post
Share on other sites

Anyone's still looking for a solution: here's a useful link http://world.episerv...&epslanguage=en pointing to this tinymce demo.. you need to click on inserting a link and go to the advanced tab. It'll be under "Relationship Page to Target"..

Good luck!

Edit: For those cannot find what needs to be added (and ruining the fun for those believing in "teach the man how to fish"):

in TinyMCEInit settings you need to add (or extend) plugins: "advlink"

Share this post


Link to post
Share on other sites

Anyone's still looking for a solution: here's a useful link http://world.episerv...&epslanguage=en pointing to this tinymce demo.. you need to click on inserting a link and go to the advanced tab. It'll be under "Relationship Page to Target"..

Good luck!

Edit: For those cannot find what needs to be added (and ruining the fun for those believing in "teach the man how to fish"):

in TinyMCEInit settings you need to add (or extend) plugins: "advlink"

The only problem is that ProcessWire TinyMCE implementation has it's own link dialog and not the standard TinyMCE one. But thanks anyway.

Share this post


Link to post
Share on other sites

Could someone please advise on a solution for the nofollow. The above solution by gandablond does, not work. I also do not want a nofollow added to every link. And when added manually, TinyMCE strips it. Thanks in advance.

If no solution is available, how do I prevent the tinymce from stripping my rel attribute?

Edited by RJay

Share this post


Link to post
Share on other sites

@RJay

Here the step to get it working. You need to enable two plugins and add the "rel" attribute to the valid elements in TinyMCE.

You can edit the configuration of TinyMCE on the field settings under the tab "Input". There's a collapsed fieldset TinyMCE Advanced  Configuration Options.

Add the two plugin contextmenu and advlink to the plugins text field:

...,contextmenu,advlink

Then in the field valid_elements add rel to the @[id|class] so it won't get stripped off:

@[id|class|rel]

Now when you have done that you go edit your text and add a link using the PW link dialog.

Then click on the link using context menu (right click) and select "Insert/Edit link". You'l be presented with a ton of attributes you can set to the link. But you need to also add them to the valid_elements first.

  • Like 2

Share this post


Link to post
Share on other sites

@Soma. You are a lifesaver :). I had previously tried to add the rel to the valid elements, but I was adding it in

a[href|target|name]

 Amazing what happens when its in the right one. I also added the advlink plugin, but it was not working properly, so I am assuming the two go hand and hand. Thanks so much for the instructions, they are greatly appreciated. 

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...