WordPress  allows commenting by default on the blog post or pages you create using WordPress. The comment area constitutes of the Name, Email, URL and Comment. Name and Email fields are mandatory but URL field is options. However, many automated bots try to exploit this feature and post some automated comments. This in result may not be good for the blog’s SEO and hence it should be avoided or stopped.

One way is to manually moderate all comments and spam the unsolicited comments, which apparently is a tedious job. The simpler way is to simply remove the URL field which won’t allow user’s to post the URL along with their comment. We are going to discuss how you can achieve this by simply adding a function in your WordPress theme file.

All you have to do is just open the file functions.php located in the themes folder and add the following piece of code at the end of the file.

function disable_comment_url($fields)
    //print_r($fields); //uncomment this to see the default value of $fields
    return $fields;

We are utilizing the filter comment_form_default_fields to change the default fields added by the function comment_form(). You can see the default content of the $fields array by using the print_r function. In the above code we have just unset the array key url and returned the array. In short we have applied a filter just before the comment form is outputted to the user. It’s worth noting that some bots may even post URLs even if you have this filter right in place, but that’s a rare chance. Good side is you are protected from manual blog commenting spam.

A neat trick to do an awesome job in WordPress. Hope that helps.

Stay Digified!!
Sachin Khosla


Share this post: