Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#35651 new defect (bug)

No longer any consistent way to add content to bottom of comments form

Reported by: smerriman's profile smerriman Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Comments Keywords: 2nd-opinion has-patch has-screenshots
Focuses: Cc:


In #34731, there was a discussion on whether comment_notes_after should be directly after the comment form (now at the top by default), or at the bottom above the submit form (as the documentation described).

The decision was to change the documentation.

However, this now leaves no consistent way for themes/plugins to add content to the bottom of the form, above the submit button. Using comment_notes_after was a popular method to add notes like terms and conditios, or a subscribe checkbox etc, and consistent with the old documentation. All of these themes/plugins that relied on the positioning in the documentation will now have this output in the wrong place in the form.

comment_form_after_fields isn't an alternative since it only applies when the user is logged out.

Attachments (3)

comment_notes_after_invalid_workaround.png (126.8 KB) - added by donmhico 5 years ago.
before_comment_form_submit_field.jpg (153.3 KB) - added by donmhico 5 years ago.
35651.diff (1.1 KB) - added by donmhico 5 years ago.

Download all attachments as: .zip

Change History (9)

#1 @rachelbaker
8 years ago

  • Keywords 2nd-opinion needs-patch added

Related: #29974, where there is also some discussion.

#2 @ocean90
8 years ago

  • Version changed from trunk to 4.4

#3 @rachelbaker
8 years ago

@smerriman What do you propose?

#4 @smerriman
8 years ago

I think an extra hook before the submit button, similar to what was proposed in #26395 (but it should be before submit, not after textarea now that it has moved). It was closed as wontfix there because there was a hacky workaround. Now there is no longer a hacky workaround.

Last edited 8 years ago by smerriman (previous) (diff)

This ticket was mentioned in Slack in #core-comments by rachelbaker. View the logs.

8 years ago

5 years ago

#6 @donmhico
5 years ago

  • Keywords has-patch has-screenshots added; needs-patch removed

A new hook action seems reasonable now. As @smerriman mentioned, the workaround provided in #26395 isn't applicable anymore.

Related: #27080

You can use comment_form_defaults filter to prepend your text to $args['comment_notes_after']:

function comment_form_after_comment_26395( $defaults ) {
	$defaults['comment_notes_after'] = '<p>SAMPLE COMMENTS NOTES AFTER</p>' . $defaults['comment_notes_after'];
	return $defaults;
add_filter( 'comment_form_defaults', 'comment_form_after_comment_26395' );

This is because comment_notes_after is no longer rendered directly at the top of the submit button. See the attached screenshot to see how the code above works.

Using the comment_form action ( won't do good as well because it is hooked after the submit button is rendered.

For now, the only way is to use the comment_form_submit_field filter ( and just append what we want there. But IMHO this is not good as that filter should really just be about the submit button itself.

In my attached patch, 35651.diff, I introduced a new action called before_comment_form_submit_field which hooked directly above the submit button.

Sample Usage:

function test_action_before_submit_field( $post_id, $args ) {
 add_action( 'before_comment_form_submit_field', 'test_action_before_submit_field', 10, 2 );

The code above will result to

Last edited 5 years ago by donmhico (previous) (diff)
Note: See TracTickets for help on using tickets.