instagram rss arrow-down

Many themes on the market use the comment_form() function to insert the comment fomr after posts. WordPress codex documentation offers a few examples of implementation, but it’s not that helpful. There are many hooks inside the function but it can be hard to find them. Available hooks can vary, the number depend on the user’s capabilities and discussion settings.

Usually, the user is not logged in but is allowed to comment. Hooks may differ is user is logged in or logged out. For this tutorial, it makes no difference, because I’m using comment_form_top which is on the same location for both scenarios.

To help you visualize the points where hooks are anchored, see the following image (for logged in users)

Six hooks are available for this scenario:

  • comment_form_before
  • comment_form_top
  • comment_form_before_fields
  • comment_form_after_fields
  • comment_form
  • comment_form_after

Simple way to add text above comment field

The code to add text above comment field is:

Where do I add this code?

You would normally add this code to your functions.php file.

If User is not logged and must be registered to comment, there will be an additional hook  comment_form_must_log_in_after available. In this case, the hook  comment_form  is left out.

In case Comments are closed you will have only one hook left  comment_form_closed  since the comment form is not being displayed.

If you like playing around with WordPress, you might also want to check out how to add cool water effect to your footer on this link.

Support New Articles with a Sweet Tee

2 comment on “How to add text above comment field in WordPress using Hooks

  • Juan
    May 3, 2018 | 3:38 pm

    Your post helped me 🙂
    Simple, quick and nice
    Thank you very much!

  • WP Brainery
    July 9, 2018 | 7:29 am

    You’re most welcome!

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

*

*