WordPress.org

Make WordPress Core

Opened 6 weeks ago

Closed 3 weeks ago

#54283 closed feature request (worksforme)

Add a hook to allow themes to remove the "Comments are closed." sentence on pages

Reported by: audrasjb Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Comments Keywords: 2nd-opinion has-patch
Focuses: Cc:

Description

Previously: #17568

By default, the comment template displays a "Comments are closed." sentence on pages.

Until now, theme authors had to create their own management of the display of comments in order to remove this mention when you are on a page with comments disabled (which is the case by default).

Today, with the arrival of Block Themes which contain as little PHP as possible, it becomes necessary to add a few more hooks on the management of comments, to allow Gutenberg to define the settings that will apply by default on the themes.

I propose to add a new comments_closed_message filter so themes and/or Gutenberg can opt-in/out displaying this message (and even edit the message itself), depending on the post type (enabled on Posts but disabled on Pages, for example).

Related discussion/PR on Twenty Twenty-Two repository: https://github.com/WordPress/twentytwentytwo/pull/127

Attachments (1)

54283.diff (1.4 KB) - added by audrasjb 6 weeks ago.
Comments: Add a hook to allow themes to remove the "Comments are closed." sentence when needed.

Download all attachments as: .zip

Change History (11)

#1 @audrasjb
6 weeks ago

  • Keywords 2nd-opinion added

#2 @Clorith
6 weeks ago

Would this not make more sense as an attribute on the comment block instead?

I'm thinking something along the lines of a "Display a message if comments are closed" toggle, that would be flexible enough for block themes to use it in any page template that is created I presume, without needing additional filtering based on content types.

I'm not against the idea of a filter here at all, just trying to think what gives the most flexibility without over-complicating.

@audrasjb
6 weeks ago

Comments: Add a hook to allow themes to remove the "Comments are closed." sentence when needed.

#3 @audrasjb
6 weeks ago

  • Keywords has-patch added; needs-patch removed

This patch can be tested using this snippet:

function mytheme_comments_closed_message( $message, $post ) {
	if ( 'page' === $post->post_type ) {
		return;
	}
	return $message;
}
add_filter( 'comments_closed_message', 'mytheme_comments_closed_message', 10, 2 );

Using this snippet, the "Comments are closed." message won't be displayed anymore on Page with comments disabled.

#4 @kjellr
6 weeks ago

Thanks, @audrasjb. I agree with @Clorith that this seems like it would make more sense to be added (if possible) within the block itself.

I've opened https://github.com/WordPress/gutenberg/issues/35732 to discuss solutions over in the Gutenberg repo too.

#5 @audrasjb
6 weeks ago

I think we need both, since it's also something useful for Classic Themes developers.

This ticket was mentioned in Slack in #core-themes by jffng. View the logs.


6 weeks ago

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 weeks ago

#8 @audrasjb
4 weeks ago

the issue was fixed in Gutenberg but I personally think it’s worth adding this filter as it would be easier for theme developers to remove this sentence without having to use a Comments Walker or even worst a display: none CSS declaration. Thoughts?

#9 @sabernhardt
4 weeks ago

I don't think we need a filter in the theme compat file, which gives a deprecation warning when the theme does not have a comments.php template.

The comments closed message is one of the common parts of comments.php, but I was able to edit/remove that within the (parent or child) theme.

#10 @audrasjb
3 weeks ago

  • Keywords needs-dev-note removed
  • Milestone 5.9 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

You're right @sabernhardt. As it was fixed upstream in Gutenberg and since we don't need any change in Core, let's close this as worksforme.

Note: See TracTickets for help on using tickets.