Add nofollow to links
-
Is there anyway to add the nofollow tag to links?
-
I would imagine that you could do this without affecting any core files through a plugin as the links portion for posts is pluggable. Now, saying that, we need someone with some experience working with the code to make this a plugin.
Trent
bbPress has a function called bb_rel_nofollow() which can be added via filter to functions which output a link (… not functions that output a URL).
For example:
add_filter('post_author_link', 'bb_rel_nofollow');
Please–can you tell me specifically where to add this? What file and which lines? (Sorry, perpetual noob, trying to learn.)
You can simply add that line into
bb-includes/default-filters.php
or
create your own plugin file with that line.
livibetter, for us noobs, can you show what a plugin would look like with just that functionality, so we could avoid modifying a core file in bb-includes?
Thanks.
Here it is:
<?php
/*
Plugin Name: My own tweak for my forums
Plugin URI: https://bbpress.org/
Description: Fine tuning codes for my forum
Author: Your name
Author URI: http://www.myforum.com/
Version: 0.1
*/
add_filter('post_author_link', 'bb_rel_nofollow');
?>Basically, you can put many fine tuning codes within one PHP files, and this file is for your forum only. Remember to activate this plugin.
If it were a _plugin, would it load automatically, and not require activation? Like, you could call it _myforumtweaks.php and it would be loaded automatically with no activation once you dropped it into my-plugins?
That’s all there is to a simple add_filter plugin, eh? (no video required…)
livibetter,
Thanks so much! It works beautifully.
I know it works on new posts, on URLs in the post.
Does it also work on URLS in old posts, when they’re viewed? I am not able to test that.
Also, it obviously doesn’t work on author’s website links (the ones saves in their user profile, I mean). How do we make those nofollow if we want to?
Many, many thanks. I am learning, but slowly.
Okay, upon further testing, it does seem to be working with older posts–in certain circumstances.
Let me explain
If you simply type (or in the past typed) in a URL, this plugin adds “nofollow.” But if you write a sentence and add a link to the text, it doesn’t. You can see this in effect here:
http://bedbugger.com/forum/topic/test-5?replies=3#post-14812
Compare the two tests of a link to google. The first, where the URL is typed in, adds nofollow, the second, where the HTML is used to link out to google, doesn’t.
Please help me fix this? Thanks again, this is a huge help!
It works great.. but a savvy spammer can bypass this simply by editing their post and adding rel=’follow’ to their a tag.. anyone know of a more complete/thorough solution?
It worked fine with me, I’ll just manually delete the entry of the spammers!
Try manually deleting a few hundred posts per day once you get popular..?
Anyone know of more thorough solution? One that permanently adds “nofollow” to all posted links??
I thought this plugin did that?
https://bbpress.org/forums/topic/add-nofollow-to-links#post-12523
Hi there,
I have tried so hard to tweak this plug in but I am unable. All I want is to add besides the nofollow is a target=”_top” so that the forum user is able to go out to another window for external links.
Can anyone help me please,
Many thanks,
by default the nofollow is there, but how can we add some more things to the tag?
cordoval, make this into a plugin:
//add target=_blank to post links
function bb_target_blank( $text ) {
$text = preg_replace('|<a (.+?)>|i', '<a $1 target="_blank">', $text);
return $text;
}
add_filter('pre_post', 'bb_target_blank');the problem was that it was not ‘post_author_link but ‘post_text
cordoval did you get it to work with links in text also? Not just URLs.
Thanks.
I know this post is rather old, but none of the above suggestions worked. The problem with using the post_author_link or even get_user_link filters is that those only filter the “href” attribute, not the entire “a” tag. That means you can’t add rel=”nofollow” using those filters.
I wasn’t able to figure out a way to get it done without editing the core. I suggest the post_author_link() function around line 1747 of bb-includes/functions.bb-template.php be edited to allow the option of only returning the link rather than echoing it. That way, you can output the author links in your template (post.php) using something like this:
<?php bb_rel_nofollow(post_author_link(false)); ?>
With the “false” parameter telling WordPress to return the link rather than echo it. I believe that would work for future releases.
As for now, I believe you’ll have to open bb-includes/function.bb-template.php and edit the post_author_link and post_author_avatar_link functions to add rel=”nofollow” to the “a” tags. Those functions begin around line 1747 of bb-includes/function.bb-template.php.
Hope that helps.
Better yet, nofollow should be the default rel attribute value. From an SEO standpoint, you’re asking for trouble allowing dofollow links unless you really feel like checking out every single users’ website and making sure it’s not a “bad neighborhood”. Even then, Google will see you as handing out links indiscriminately and will probably take away any pagerank your pages might have had.
jcrens8392, if you would like this included in future versions, please open a ticket at trac: http://trac.bbpress.org – you can log in there with a wordpress.org username and password.
Hi,
since i have the forum in a different frame of my page, i’d have to add the attribute “target_top” to every link.
The code below is only for target_blank, or would it be possible to replace every “blank” with “top” and have it working?
https://bbpress.org/forums/topic/add-nofollow-to-links#post-17523″
And how do you make the code into a plugin? you copy and paste into a text file, save it as *.php and upload the file in the bbpress plugins folder?
Thank you very much, every help is very appreciated!
The Process
If you want all links in your posts to be nofollow, you have to use post_text instead of post_author_link
Here you go
<?php
/*
Plugin Name: My own tweak for my forums
Plugin URI: https://bbpress.org/
Description: Fine tuning codes for my forum
Author: Your name
Author URI: http://www.myforum.com/
Version: 0.1
*/
add_filter(‘post_text’, ‘bb_rel_nofollow’);
?>
I guess that’s what most people want to do
thank you! thank you!!!!! works perfectly
I don’t think adding nofollow tag is a good idea on your site. For a forum, dofollow feature will give you many original contents.
- You must be logged in to reply to this topic.