Archived topic
How to add line/section to the comments section?
5 replies · Started by Eugene on September 19, 2021
Hi there,
Could you help with how to add a line/section to the comments section?
I have a "Website" section removed (a long time ago), but I just want to add "Model Number" section instead.
it should not be a link, just a text. And I want to see a "Model Number" in the comments section in the dashboard.


Hi Eugene,
To clarify: is the "Model Number" a field? or a dynamic text?
While waiting for reply:
We generally modify the leave comment form using comment_form_default_fields filter (PHP).
Here's an example usage:
Removing URL field and change email and name placeholder text.
add_filter( 'comment_form_default_fields', function($fields){
$commenter = wp_get_current_commenter();
$required = get_option( 'require_name_email' );
$fields['author'] = sprintf(
'<label for="author" class="screen-reader-text">%1$s</label><input placeholder="%1$s%3$s" id="author" name="author" type="text" value="%2$s" size="30" />',
esc_html__( 'First Name', 'generatepress' ),
esc_attr( $commenter['comment_author'] ),
$required ? ' *' : ''
);
$fields['email'] = sprintf(
'<label for="email" class="screen-reader-text">%1$s</label><input placeholder="%1$s%3$s" id="email" name="email" type="email" value="%2$s" size="30" />',
esc_html__( 'Email (won’t be published)', 'generatepress' ),
esc_attr( $commenter['comment_author_email'] ),
$required ? ' *' : ''
);
$fields['url'] = '';
return $fields;
}, 20, 1 );
Hello Elvin,
Thanks for the replay..
It is a field...
Is this code above can do what I was asking?
I just need to add hook and modify this section from "first name" to 'model number"?
$fields['author'] = sprintf(
'<label for="author" class="screen-reader-text">%1$s</label><input placeholder="%1$s%3$s" id="author" name="author" type="text" value="%2$s" size="30" />',
esc_html__( 'First Name', 'generatepress' ),
esc_attr( $commenter['comment_author'] ),
$required ? ' *' : ''
Hi there,
the code that Elvin provided simply allows you to filter the default comment fields.
To add you own custom field would require custom developement as you not only need to add the field on the front end, but also the backend and update the Post meta on submit. I found this article which explains how to do that:
https://wpsites.net/web-design/add-remove-change-order-of-comment-form-default-fields/
Thank you
You're welcome