Add a note to your comment form

Here’s a code snippet you might find useful if you ever want to add a message to your comment form to display posting rules or something similar.

We simply create a function that adds a custom message and hooks into the comment form and add it to our functions.php. There are several hooks available for logged in, loggged out and comments closed.

User is logged in hooks.

  • comment_form_before
  • comment_form_top
  • comment_form_after_fields
  • comment_form
  • comment_form_after

Not logged in and must be logged in to post hooks.

  • comment_form_before
  • comment_form_after
  • comment_form_must_log_in_after

Comments Closed hook

  • comment_form_closed

Select where you want to place the message by changing the hook in line 2.

// Add a note above the comment form
add_action( 'comment_form_top', 'comment_notes' );
function comment_notes() {
?>
<div class="comment_notes"><?php echo "Here is a message I want to show users when they leave a comment."; ?></div>
<style type="text/css">
.comment_notes{
	font-family: Helvetica, Arial, sans-serif;
	font-size:13px;
	font-weight: bold;
	color:red;
}
</style>
<?php
}

16 thoughts on “Add a note to your comment form

  1. kyrul

    can i ask something. i already istalled nomnom child theme,but i have problem in sidebar css. its a little bit have padding there. can i set my style.css file to delete the padding . hope you can help me :)

  2. Geoff

    I have to say as well that can Iask something. I currently installed nomnom child theme,but I have problem in sidebar css. its a small little bit have padding there. can i set my design.css file to delete the padding .

    1. Zeaks

      You can use any of these hooks
      comment_form_before
      comment_form_must_log_in_after
      comment_form_top
      comment_form_logged_in_after
      comment_form_before_fields
      comment_form_after_fields
      comment_form
      comment_form_after
      comment_form_comments_closed

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*