Site logo

Archived topic

How to add line/section to the comments section?

5 replies · Started by Eugene on September 19, 2021

Viewing posts 1–6 of 6

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.
LG-Washer-Code-d-E-Troubleshooting-Guide-DIY-Appliance-Repairs-Home-Repair-Tips-and-Tricks-2021-09-1
Comments-1-DIY-Appliance-Repairs-Home-Repair-Tips-and-Tricks-Word-Press-2021-09-19-20-01-54

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 ? ' *' : ''

Thank you

You're welcome

This archived topic is closed to new replies.