I've noticed that in your forum you simply don't allow links, smart
But in my forum I think it makes more sense to allow them. So my question is - how do I set bbPress to automatically add the nofollow tag to links posted by my forum users? I haven't been able to find a plugin...
We Rock Your Web Forum » Content Management Systems
Add nofollow to bbpress links?
(7 posts)-
Posted 2 years ago #
-
Posted 2 years ago
-
You can easily create the plugin yourself without having to hack the bbPress core files. Simply create a folder named "nofollow" in your example.com/bbpress/my-plugins directory and add a file named nofollow.php to it. The nofollow file should contain the following:
<?php
/*
Plugin Name: Nofollow
Plugin URI: http://bbpress.org/
Description: Adds nofollow to user links
Author: CWDNow.com
Author URI: http://www.cwdnow.com/
Version: 0.1
*/add_filter('pre_post', 'bb_rel_nofollow');
?>When you're done, sign in to your forum as admin, and activate your new nofollow plugin. You'll notice that all links, whether they're created using tags or generated automatically by bbPress' "make url's clickable" function, will have rel="nofollow" tags in place.
Posted 2 years ago # -
Thanks. The nofollow is now added to all text as well as clickable links. However, when I add the bbcode plugin (bbcode-lite and bbcode-buttons), the URL that is entered by users, and subsequently converted into a clickable link, does not have the nofollow tag appended. Sigh - any ideas how to make this work? I tried adding the bb_rel_nofollow filter everywhere, but no luck.
Posted 2 years ago # -
Good question. It looks like for now the only way to nofollow links generated via the bbcode module is to modify the BBcode-lite.php file, within the bbcode-lite plugin directory, as follows (rel="nofollow" additions in bold). This starts on line 43:
foreach($bbcode_lite['wrap'] as $bbcode=>$html){$text = preg_replace('/\['.$bbcode.'=(.+?)\](.+?)\[\/'.$bbcode.'\]/is','<'.$html[0].' '.$html[1].'="$1" rel="nofollow">$2</'.$html[0].'>',$text);}...
foreach($bbcode_lite['complex'] as $bbcode=>$html){
if($bbcode!='url') {$text = preg_replace('/\['.$bbcode.'\](.+?)\[\/'.$bbcode.'\]/is','<'.$html[0].' '.$html[1].'="$1">',$text);}
else {$text = preg_replace('/\['.$bbcode.'\](.+?)\[\/'.$bbcode.'\]/is','<'.$html[0].' '.$html[1].'="$1" rel="nofollow">$1</'.$html[0].'>',$text);}
} /* cwd */For every possible link creation scenario we've added a nofollow. If you wish to tweak this, you can remove nofollow for instances where you don't need it.
Note that you don't need it for
$bbcode_lite['simple'], as that is not for anchor link tags, but rather for markup (strong, em, code, etc.)Posted 2 years ago # -
Nice - that worked, thanks. Wow, CWD Forums are responsive!
A hate to keep bugging you, but I just ran into one last thing - how do we get the nofollow to take hold in signature posts? Ie. when a user posts, they can, in their profile page, leave a link in their signature that appears below all their posts. This is enabled via the bbPress Signatures module.
Posted 2 years ago # -
Simply add
add_filter('post_text', 'bb_rel_nofollow');towards the top of your bb-signatures.php (within your bbpress-signatures/ plugin folder) file. You can use this approach anywhere (ie. in any plugin) where you want nofollow added to links that are generated.Posted 2 years ago # -
Looks like bbPress 1.0.3 and above automatically nofollow all links. If you want to add links without "nofollow," the only way I see of doing this is via phpMyAdmin (editing a post in the DB). Does anyone else know of a way to create a link in bbPress that isn't automatically nofollowed?
Posted 10 months ago #