WordPress: Add notes to the comment form

Most themes use the comment_form action which can be used to add arbitrary things to the comment form with a plugin. This post presents a simple plugin that uses custom fields to add special notes to this section.

You can download the plugin here, unzip it, upload it to your wp-content/plugins directory and activate it.

How to

Using this plugin is super simple: just add a custom field named cnote to a post/page and enter the content that should appear next to the comment form into its value field.

Here’s an example:

Custom Field

When WordPress renders the page, the plugin will pick up the content of your custom field and display its content next to your comment form. It may look like so:

Result

The plugin expects that you enter some text, so it inserts your content into a p element. This element has got a class cnote helping you to style the notes with CSS.

The code

In case you’re developer and want to know more about the code just have a look at the plugin, it’s really straight forward. What it does is this: look out for a custom field named cnote, if it’s present we’ll output it’s contents otherwise nothing happens.

$note = get_post_meta($post_id, 'cnote', true);
if (empty($note)) return;
echo '<p>', $note, '</p>';

This gets registered with the comment_form action and will be executed once the theme calls this action.

Conclusion

Using custom fields we can add hints to comment forms on a post/page basis. This technique may be really helpful in case you would like to tell the user something special just before he fills out the comment form.

1 thought on “WordPress: Add notes to the comment form”

Comments are closed.