Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mike3k on
This won't actually prevent spam from being posted, but it will eliminate any incentive to spam. Google announced a new attribute which will prevent a link from raising a site's ranking. If all user-posted links have 'rel=nofollow' added, posting a comment on your site will have no effect on the poster's site. A simple patch to filter.module will automatically append it to any link in a user's post.
Add the following line near the end of the function _filter_html, just before the line return trim($text)
$text = preg_replace(’|<a.+href=([^>]*)>|’,'<a href=$1 rel="nofollow">’,$text);
I've implemented this patch at both macmegasite & worldbeatplanet.
Comments
Won't this affect nodes
Won't this affect nodes posted using the standard html filter? Is there any way to do this to comments only?
Yes, it does affect nodes.
Yes, it does affect nodes. I'm not sure if it's possible to limit it to comments only. However, if you use full HTML instead of filtered HTML the links will be unchanged. If you limit full HTML to only registered users or add another role to allow it, anonymous users are forced to use the filter.
--
Mike Cohen, http://www.mcdevzone.com/