Using WordPress ‘comment_form_comments_closed’ PHP action

The comment_form_comments_closed WordPress PHP action fires after the comment form if comments are closed.

Usage

add_action('comment_form_comments_closed', 'your_custom_function');
function your_custom_function() {
// your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: comment_form_comments_closed

Examples

Display a message when comments are closed

Display a custom message to users when the comments are closed.

add_action('comment_form_comments_closed', 'display_comments_closed_message');
function display_comments_closed_message() {
echo "<p><strong>Comments are closed for this post. Please check back later for new discussions.</strong></p>";
}

Show a contact form when comments are closed

Display a contact form for users to get in touch with the website owner when comments are closed.

add_action('comment_form_comments_closed', 'show_contact_form');
function show_contact_form() {
echo do_shortcode('[contact-form-7 id="123" title="Contact form"]');
}

Display a call to action when comments are closed

Encourage users to join your newsletter when comments are closed on a post.

add_action('comment_form_comments_closed', 'display_newsletter_cta');

function display_newsletter_cta() {
    echo "<p><strong>Join our newsletter to stay updated on the latest discussions and more!</strong></p>";
    echo do_shortcode('[newsletter_signup_form]');
}

Display a list of related posts to keep users engaged when comments are closed.

add_action('comment_form_comments_closed', 'display_related_posts');
function display_related_posts() {
if (function_exists('related_posts')) {
related_posts();
}
}

Show social sharing buttons when comments are closed

Display social sharing buttons for users to share the post when comments are closed.

add_action('comment_form_comments_closed', 'display_social_sharing_buttons');
function display_social_sharing_buttons() {
echo do_shortcode('[social_sharing_buttons]');
}