Make WordPress Core

#54283 closed feature request (worksforme)

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

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


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:

Attachments (1)

54283.diff (1.4 KB) - added by audrasjb 20 months 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
20 months ago

  • Keywords 2nd-opinion added

#2 @Clorith
20 months 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.

20 months ago

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

#3 @audrasjb
20 months 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 $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
20 months 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 to discuss solutions over in the Gutenberg repo too.

#5 @audrasjb
20 months 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.

20 months ago

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

20 months ago

#8 @audrasjb
20 months 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
19 months 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
19 months 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.