Have you came across that annoying moment, when a commenter starts posting unwanted and irrelevant links in comments that survive from Akismet spam filtering? WordPress users who experience a lot of comment spam can filter out spam through Akismet. But sometimes, some unwanted link postings in comment are not detected by Akismet.

As a blogger and WordPress user, I experienced this thing several times. If you want to get rid of such unwanted spam postings, or it could be your policy to restrict users to post links in comments, 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;
    $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.