[Tip/Trick] Add "nofollow" for external links

Started by Neo_TE, July 17, 2013, 02:04:33 PM

Previous topic - Next topic

Neo_TE

A better implementation of this feature is available in this thread, http://www.simplemachines.org/community/index.php?topic=510778.0.



QuoteWarning:
FYI, this trick adds nofollow for all automatically parsed links (i.e. links that are not wrapped within url or iurl tags), irrespective of whether they're internal or external links.

To overcome that issue, I made a mod (its yet to be approved) and you may checkout the features of that mod in this link, http://www.simplemachines.org/community/index.php?topic=508093.


Tip/Trick to add "nofollow" option for external links. Do the following edits in ~/Sources/Subs.php


Find:
Code (find) Select
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',

Replace:
Code (replace) Select
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank" rel="nofollow">$1</a>',




Find:
Code (find) Select
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank">',

Replace:
Code (replace) Select
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank" rel="nofollow">',




How-To

  • Use "url" tags for external links
  • Use "iurl" tags for links within your website

Colin

This is awesome. Thank you so much for taking the time to post this xPandax.
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Mick.


Mick.

Reminds of Wikipedia. Their out links are the same. No follow.


Neo_TE


gr8shivam

I have my forum on a subdomain. Will this trick change the links that are linking to my domain to nofollow?

Colin

Quote from: gr8shivam on July 21, 2013, 01:25:36 AM
I have my forum on a subdomain. Will this trick change the links that are linking to my domain to nofollow?

Yes, it will for all links.
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Neo_TE

Since this trick, adds nofollow for all automatically parsed links, irrespective of whether they're internal or external links, I made a mod that differentiates the internal links from external links and

  • automatically adds "iurl" tag for internal links, so that internal links are opened in the same window
  • automatically adds "nofollow" only for external links

Check this thread, http://www.simplemachines.org/community/index.php?topic=508093.  Feedback appreciated. Thanks.

SKSLink.com

My script code looks different for a version SMF 2.0.4:
   ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" class="bbc_link">$1</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               $data = strtr($data, array(\'<br />\' => \'\'));
               if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
                  $data = \'http://\' . $data;
            '),
         ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_equals',
            'before' => '<a href="$1" class="bbc_link">',
            'after' => '</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               if (substr($data, 0, 1) == \'#\')
                  $data = \'#post_\' . substr($data, 1);
               elseif (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
                  $data = \'http://\' . $data;
            '),

Neo_TE

Quote from: SKSLink.com on August 03, 2013, 02:11:18 PM
My script code looks different for a version SMF 2.0.4:

You searched for

'tag' => 'iurl',

You should actually search for 'tag' => 'url',


FYI, this trick adds nofollow for all automatically parsed links, irrespective of whether they're internal or external links.



jackkbu



Devpro

This is great. And really useful. I love it.

Neo_TE


Cheat

Sorry for the huge bump, but I had been struggling with making external links nofollow and internal ones followed, so I thought I would drop in and let everybody know how I did it.

1. Do what OP says. All links will be nofollow.

2. In Display.template.php of your template add the following code after:

// Show the post itself, finally!

Or really anywhere before the post body is rendered. For this next bit of code, I am checking for my site (sep7agon.net). You should replace the "sep7agon" and "net" with your respective domain name/TLD.


// Do some filters for external links...
        $temp_content = $message['body'];
        $preg_pattern = '~<a\shref\s?=\s?"http([^\.]+)sep7agon\.net([^>]+)>~';
        $temp_content = preg_replace_callback(
            $preg_pattern,
            function($match){
                return str_replace('rel="nofollow"', '', $match[0]);
            },
        $temp_content
        );
       
        $message['body'] = $temp_content;
Sep7agon.net [nofollow] | Off-topic and Gaming Site


Wellwisher

Neo_TE made a mod of this trick, does anyone have it please? I can't be bothered to make edits?  :P Someone attach it here?

Went to the op link:
http://www.simplemachines.org/community/index.php?topic=510778.0

His Mod:
http://custom.simplemachines.org/mods/index.php?mod=3767

it says "Sorry but no mod was found"?

Advertisement: