BIOS,Windows, Linux, Software,Security, Domains, Web Hosting

Remove Links from Comments in Wordpress

There are more and more spammers in my another wordpress blog, they post various comments with some links in it, few of them are useful for my article. So I want to remove these links in comments. I have no other choose as long as I am using wordpress.


  • Removing links in comments will affect all the comments in your wordpress, including all the regular(good) comments.
  • All the removing actions only affect the display, not the data in database, you cancelled the removing anytime.

1. Remove links in wordpress comments

Add these codes in your current theme's function.php file. Just before some other add_action or add_filter syntaxs.

function remove_links_in_comments($text = ''){
    $text = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$text);
    echo $text;

add_filter('comment_text', 'remove_links_in_comments', 10);

2. Remove comment author links in wordpress comments

Note: this action will remove all the author links in comments, if you want to display the author links again, just delete these codes and refresh your page.

function remove_comment_author_url($text = '') {
    $text = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$text);
    echo $text;

add_filter('get_comment_author_link', 'remove_comment_author_url', 20);


Leave a Reply

Subscribe to BootBeta Comments RSS feed to receive notification of latest comments posted.


  • Enter Email Address:

Recent Post

Copyright@ 2010-2014 Bootbeta All Rights Reserved.
HooBlog Ver 1.5 Build 20140530