MyBB Community Forums

Full Version: Plugin Hook: nofollow links
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, i wanna modify some links before sending page output. I'm using Google SEO Plugin, that works correctly. At the top of this plugin, I simply added the following code:

$plugins->add_hook("pre_output_page", "seo_change_links");

Inside the same file, I put my function code:

function seo_change_links($page)
{
	global $mybb;
		
	$page = preg_replace("#(<a.+?href=.+?(search|stats|usercp2|printthread|sendthread|showteam|memberlist|calendar|member|online|private|newreply|newthread|showthread|forumdisplay)\.php)(.+?)>(.+?)</a>#e", "seo_add_nofollow('\\1', '\\3', '\\4')", $page);
	return $page;
}

/**
 * Adds rel="nofollow" in the data provided by matches 
 * in parts.
 * 
 * @access private
 */
function seo_add_nofollow($part_1, $part_2, $part_3)
{
	return stripslashes($part_1) . stripslashes($part_2) . ' rel="nofollow">'. stripslashes($part_3) .'</a>';
}

I wanna adding the nofollow attribute to some links that I don't want show to search engines, like Google.

But... the forum index page appears blank... looking to the http headers, I found a 301 error (moved permanently)... other pages (like forums and threads) works fine and all the links are nofollow!

If I remove my code, all works again! How can I fix this bug?

Thanks a lot and sorry for my english Smile
(2009-08-31, 06:26 PM)michx Wrote: [ -> ]I wanna adding the nofollow attribute to some links that I don't want show to search engines, like Google.

nofollow does not prevent anything from showing up in search engines. If it's your own site, block things you don't want to show with robots.txt.
I used also the robots.txt file. But, I wanna understand the MyBB "Mind" Smile
Is there any solution?

P.S: Thanks chutz for your comment Wink
Michx, did you ever fix your script? Adding the no follow to user posted outbound links will help with SEO.

Regarding the MyBB mind as you put it. Somewhere in the code MyBB adds target="_blank" to all out bound links. I wonder if we can hack or piggy back on that code to add rel="nofollow"