Support » Everything else WordPress » How to add a notice below comment form?

  • I want to add a simple text notice below the comment submission form, but I only want it to show when comments are actually allowed on a post and not all the time. What code do I need to achieve this in the comments.php template?

    Currently, if I just write some HTML below the comment_form() then it shows regardless of whether comments are enabled or not for a post, which is not what I want. I only want to show the text when comments are enabled.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda



    Hi there!

    My first question is how are you adding that HTML? Are you using a plugin or via the theme?

    If you are familiar and comfortable with using hooks you can definitely take a look at what hooks and filters the comment_form() template tag has available. The one that might be useful would be the comment_form_after .

    Hopefully that helps steer you in the right direction, if not don’t hesitate to ask for more guidance.

    Thread Starter ispreview


    I eventually found the easiest way was to just put it inside an if statement at the bottom of the comments.php file.

    <?php if ( comments_open() ) : ?>

    However, I now have one problem left to solve. I want to put a simple “Comments are closed” message on POSTs where there are NO (0) comments and the comments are closed. The comments template I’m using can actually do something like this for situations where comments exist, but the comments are now closed:

    		// If comments are closed and there are comments, let's leave a little note, shall we?
    	if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    	<p class="no-comments" align="center"><?php _e( '<strong>Comments are closed</strong>', 'twentysixteen' ); ?></p>
    	<?php endif; ?>

    But I’m not sure how to adapt this code so I can do the same thing on posts where there are NO comments and the comments are closed? Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.