Steps
- Add the PHP code to your theme’s
functions.php. - Save the changes.
- Open a post where comments are disabled.
- The custom message will be displayed instead of the comments section.
/**
* Display a custom message when comments are closed
*/
function custom_comments_closed_message( $comments_open, $post_id ) {
if ( ! $comments_open && get_post_type( $post_id ) === 'post' ) {
add_filter(
'comments_template',
function () {
echo '<p class="comments-closed-message">Comments are currently closed for this post.</p>';
return false;
}
);
}
return $comments_open;
}
add_filter(
'comments_open',
'custom_comments_closed_message',
10,
2
);
Tested on
WordPress 6.8
Reported by the author on October 1, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.3. It may still work.