Remove URL or website field from WordPress comment form

In WordPress comment form section for posts or pages, we can see a website URL field. Many of the WordPress bloggers may not like to keep this field. This is because spammers use it to spam.

It is noted that after removing the website field, the comments from users decreases significantly. That means those who come to comment, a huge number of those commenters have the intention of spamming.

For this reason, it is better to remove the comment field. There is some plugin available that can remove the URL or website field from the comment form. But in this article, I am not going to suggest you not to use a plugin. Also, this is a programming blog. So, it is better to tell you how to do it by writing code. There is no meaning of using a plugin for this simple task that can be done just within 4 or 5 lines of code.

Yes, to remove the website field from the WordPress comment form can be done with few lines of PHP code. Below is given the PHP code that can remove the website URL field from the comment form:

function cspd_remove_comment_website_field($fields) {
    // Remove the website URL field from comment form
    // Return the fields
    return $fields;

In the above code, we use the add_filter hook and pass the comment_form_default_fields which is the default WordPress function that contains the fields of the comment form.

Use this PHP code in a plugin specific file or in the theme’s functions.php file.

Now you can check your WordPress site and find that the website field has been disappeared. This will significantly discourage link spammers from spamming on your WordPress site.

I think this is the best way to remove the website URL field from the comment form. Also, let me know what you think about this.

Leave a Reply

Your email address will not be published. Required fields are marked *