Advertisement:

Author Topic: [Tip/Trick] Add "nofollow" for external links  (Read 29677 times)

Neo_TE

  • Guest
[Tip/Trick] Add "nofollow" for external links
« on: July 17, 2013, 02:04:33 PM »
A better implementation of this feature is available in this thread, http://www.simplemachines.org/community/index.php?topic=510778.0.



Quote
Warning:
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
« Last Edit: September 07, 2013, 06:03:43 AM by xPandax »

Offline Colin

  • Lead Developer
  • SMF Hero
  • *
  • Posts: 7,767
  • Gender: Male
  • SMF Developer
    • colinschoen on GitHub
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #1 on: July 17, 2013, 02:22:46 PM »
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

Offline Mick.

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,673
  • Gender: Male
  • Premium SMF Themes
    • idesign360 on Facebook
    • @idesign360 on Twitter
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #2 on: July 17, 2013, 04:43:54 PM »
Nicely done.

Offline Mick.

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,673
  • Gender: Male
  • Premium SMF Themes
    • idesign360 on Facebook
    • @idesign360 on Twitter
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #3 on: July 17, 2013, 04:45:02 PM »
Reminds of Wikipedia. Their out links are the same. No follow.

Neo_TE

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #4 on: July 18, 2013, 12:53:19 AM »
Thank you. :)

Neo_TE

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #5 on: July 20, 2013, 02:04:24 AM »
This is awesome. Thanks. I love it :D
I'm glad to hear that and you're welcome.

gr8shivam

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #6 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?

Offline Colin

  • Lead Developer
  • SMF Hero
  • *
  • Posts: 7,767
  • Gender: Male
  • SMF Developer
    • colinschoen on GitHub
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #7 on: July 21, 2013, 04:21:08 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

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #8 on: July 21, 2013, 08:38:55 AM »
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.

Offline SKSLink.com

  • Semi-Newbie
  • *
  • Posts: 15
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #9 on: August 03, 2013, 02:11:18 PM »
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

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #10 on: August 04, 2013, 03:50:00 AM »
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.

Offline Burke ♞ Knight

  • SMF Hero
  • ******
  • Posts: 3,534
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #11 on: August 04, 2013, 12:10:41 PM »
Nice tip, my friend. :)

Neo_TE

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #12 on: August 04, 2013, 11:06:08 PM »
Thank you very much.

Offline jackkbu

  • Newbie
  • *
  • Posts: 2
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #13 on: August 06, 2013, 02:15:58 AM »
Thanks for the knowledge.

Neo_TE

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #14 on: August 06, 2013, 03:40:12 AM »
Thank you very much.

Offline Devpro

  • Newbie
  • *
  • Posts: 7
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #15 on: August 23, 2013, 06:55:05 AM »
This is great. And really useful. I love it.

Neo_TE

  • Guest
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #16 on: September 07, 2013, 06:02:45 AM »
A better implementation of this feature is available in this thread, http://www.simplemachines.org/community/index.php?topic=510778.0.

Offline Cheat

  • Semi-Newbie
  • *
  • Posts: 23
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #17 on: May 22, 2016, 01:46:01 PM »
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.

Code: [Select]
// 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

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,101
    • @studyforceps on Twitter
    • Study Force
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #18 on: June 11, 2016, 11:52:33 AM »
Thx

Offline Wellwisher

  • Jr. Member
  • **
  • Posts: 370
  • Gender: Male
Re: [Tip/Trick] Add "nofollow" for external links
« Reply #19 on: July 25, 2016, 10:39:16 PM »
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"?