Adding custom fields to the comment form on your WordPress site can be very useful for collecting additional information from your users. In this guide, we show two ways to do it: the first is by using custom code and the second is by using the Comments Extra Fields plugin.
Add custom fields using custom code:
Step 1: Open the functions.php file of your active theme using the webFTP manager.
How to access webFTP
Once inside your FTP, you must go to the files of the theme installed on your WordPress. The default path is /web/wp-content/themes/theme-name
Step 2: Add the following code at the end of the file to create a custom text field:
function agregar_campos_personalizados_comentarios($campos) {
$campos['nombre_campo'] = 'Label text';
return $campos;
}
add_filter('comment_form_default_fields', 'agregar_campos_personalizados_comentarios');
Replace "nombre_campo" and "Label text" with the name and label of the custom field you want to add.
The label text is the text that appears inside the field as an example placeholder.
Step 3: Save the changes and refresh your website. You should now see the new custom field in the comment form.
We hope this guide has been helpful for adding custom fields to the comment form on your WordPress site.