Disable Hyperlinks in WordPress Comments

a minute read

Have you came across that annoying moment, when commenters start posting plethora of unwanted and irrelevant links in comments? WordPress users who experience a lot of comment spam can filter out spam through Akismet. But sometimes, such spam comments bypass and survive the Akismet check too.

As a blogger and WordPress user, I experienced this several times. If you want to get rid of such unwanted spam postings, the first thing that you come up with is to restrict users from posting links in comments. To do that, you just need to fork up the functions.php file of your WordPress theme a little bit.

Add the below code in your WordPress theme’s functions.php just before the closing PHP tag, i.e. ?> and save the changes:

add_filter('pre_comment_content', 'strip_comment_links');
function strip_comment_links($content) {
    global $allowedtags;
    $tags = $allowedtags;
    unset($tags['a']);
    $content = addslashes(wp_kses(stripslashes($content), $tags));
    return $content;
}

That’s it! From now, commenters won’t be able to post links in comments and the previously posted links in comments will also be deactivated after saving the changes.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

There are times when you need to disable comments on your WordPress site. There are two cases contextual to disabling WordPress comments: Disabling comments for individual posts and pages Disabling comments completely Disabling comments for individual WordPr...
The default WordPress search is the only thing that used to annoy me a lot and I wasn’t using it on any of my WordPress sites. There are a number of reasons back then to stop using WordPress search feature, and the best one for me was it throwing unrelated lin...
WordPress automatically adds its current Version number to the head section of the themes. If you view the source of a WordPress-based website, you may find out the WordPress version it is using. Below given is the meta tag that carries that version informatio...