Do you want to remove your WordPress site’s Comments input fields (Name, Email, and Website/URL)? This process may sound complex; however, we’re here to guide you through a straightforward method that consolidates multiple steps into one, using just a single function.
The current article is "6.14. Remove All the Fields" of our Complete SEO Guide Box.
Previous Article: 6.13. Remove the Website Field. Next Article: 6.15. Turn Off Storing the IP
Contents
Understanding Comments Input Fields
Regarding WordPress, the default comment form presents three fields for the user to fill in: Name, Email, and Website/URL. You might want to simplify this process by removing these fields in specific scenarios. In the previous article series on removing input fields, we showed how to employ a separate function for each: How to Remove the Name Field in WordPress, How to Remove the Email Field in WordPress, and How to Remove the Website Field in WordPress. In each article, we describe the pros and cons of removing each field and why we recommend removing them.
Merging Processes: A Single Function Approach
Rather than using separate functions to remove comments input fields, we’ll walk you through a process that allows you to do it all in one function.
Dive into the Code: A Step-by-Step Guide
Edit your Child Theme functions.php file, and if you already have a code for single field removal, you can delete it. If not, find the end of the file with the “?>” string.
Before that string, make at least three empty lines and paste the code:
// Disable Website, Email, and Name in comments. 60 is the priority of execution.
add_filter( 'comment_form_default_fields', 'remove_comment_fields', 60 );
function remove_comment_fields( $fields ) {
if(isset($fields['author']))
unset($fields['author']);
if(isset($fields['email']))
unset($fields['email']);
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
This function checks if the ‘author,’ ’email,’ and ‘url’ (website) fields are set, and if they are, it unsets (or removes) them.
Click [Update File].
Clear all the caches if you use them.
Suppose there are already comments on your site. In that case, you must remove these fields from the database using Database Manager. Remember to back up your database before making any changes.
Understanding the Function
It’s essential to understand what this function does to remove comments input fields:
The ‘add_filter‘ function is a WordPress function that alters specific types of data before it’s sent to the database or the browser.
‘comment_form_default_fields‘ is the filter that allows you to change the default comment form fields.
‘remove_comment_fields‘ is the name of the function we’ve created.
Within the ‘remove_comment_fields‘ function, ‘$fields‘ is an array that holds all the default fields (Name, Email, and Website). The PHP ‘unset‘ function removes these fields from the array, effectively hiding them from the comment form.
After this process, the function returns the updated ‘$fields‘ array, which WordPress uses to render the comment form. With this method, you can easily remove comments input fields, making your website more user-friendly and less demanding of personal information.
The current article is "6.14. Remove All the Fields" of our Complete SEO Guide Box.
Previous Article: 6.13. Remove the Website Field. Next Article: 6.15. Turn Off Storing the IP
If you find any mistakes or have ideas for improvement, please follow the email on the Contact page.