Back to Top

Adding a Comment Formatting Guidelines for Visitors

Previous Post:

Adding a Comment Formatting Guidelines for Visitors

By default WordPress allows your visitors to post certain kinds of HTML markups and attributes in comments, and normally those white-listed markups and attributes are displayed to help your visitors comment properly, as shown in Twenty Ten — the default WordPress theme:

Twenty Ten Formatting Guidelineswp-content/uploads/2011/02/a67-twenty-ten-guidelines.gif 671w" sizes="(max-width: 300px) 100vw, 300px" />

Twenty Ten Formatting Guidelines

That’s the most basic form of a comment formatting guideline that you can add to a comment form. If you don’t use comment_form() function in your theme (added in WordPress 3.0), you can manually add the above guideline to comments.php, like so:

	echo '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>';

While such snippet can be enough for most websites/blogs, you should consider adding more guidelines, for example:

Drupal Formatting Guidelineswp-content/uploads/2011/02/a67-drupal-guidelines.gif 643w" sizes="(max-width: 300px) 100vw, 300px" />

Drupal Formatting Guidelines

Much nicer, eh? To have those guidelines, simply use this:

<div class="comment-guidelines">
		<li><?php _e('Web page addresses and e-mail addresses turn into links automatically.'); ?></li>
		<li><?php printf(__('Allowed HTML tags: %s'), allowed_tags()); ?></li>
		<li><?php _e('Lines and paragraphs break automatically.'); ?></li>

and make sure you have some nice CSS rules for the container, too ;).

Now what if you want those guidelines to appear only when your visitors click or hover on the textarea, just like the comment form on Javascript is the answer!

The first thing to do is, of course, hide the guidelines, in your CSS file:

.comment-guidelines {
	display: none;

Assuming that you have a common.js file and jQuery that are enqueued correctly, all you have to do is to add this to common.js:

	/* Comment guidelines */

Refresh the page and you should see the guidelines quickly fade in when you click on the textarea and they will quickly fade out again when you click outside of the textarea.

That might look cool already, but you can of course make it look more professional by adding additional CSS rules. In my opinion you should make the comment-guidelines container float or position it using absolute positioning. Another thing is, when a visitor click on a reply link, the width for comment-guidelines will be narrower (in most cases), so please keep that in mind!

Take Social Sharing to
the Next Level with Monarch!

Take Social Sharing to the Next Level with Monarch!
Print Article Trackback Trackback to this Article   Subscribe to Comments RSS Subscribe to Comments RSS

10 Opinions for Adding a Comment Formatting Guidelines for Visitors

  1. User's Gravatar
    DP April 11, 2011 at 9:12 pm – Permalink

    I’ve been googling forever and I still can’t find how to simply make comment text appear bold when it’s not my blog. It sounds so simple, but I really don’t want to hop on someone’s blog and try out what I think the syntax should be until I get it right, but I will if I have to. All the advice out there is how to manage your own blog. Am I doomed to post every comment forever in plain text only?

    I want advice for visitors, not advice for WordPress bloggers.

    • User's Gravatar
      OddOneOut April 11, 2011 at 9:32 pm – Permalink

      Hi DP!

      You know what, you are talking about the very problem that I did worry about when writing this. It is indeed a blogger’s task to tell visitors how to use mark ups (or HTML in this case). That’s why I wrote this to encourage blog owners to show common visitors how to have a ‘cool’ comment.

      I’m sorry that you couldn’t find what you expected to see here (I guess the keywords you searched for were comment formatting guidelines or wordpress comment formatting guidelines :)). WordPress’s comments are all about HTML, and there is actually a very good guide that will tell you explicitly how to use HTML markups in comments (you just didn’t use the right keywords ;).)

      Hope that helps!

  2. User's Gravatar
    yassir July 30, 2011 at 11:48 pm – Permalink

    hi, thank you!

  3. User's Gravatar
    SCTC August 24, 2011 at 6:13 pm – Permalink

    thanks for this guide really very informative and interesting looking forward to many more WP tutorials. Makes life as a blogger easier 🙂

  4. User's Gravatar
    Katherine Lindholm September 23, 2011 at 5:30 pm – Permalink

    Another WordPress tutorial about comment formatting. When I read it, it’s just simple but knowing that there’s a syntax or the basic html, I know I’m not expert on this.

  5. User's Gravatar
    Alice Isabell September 27, 2011 at 6:11 pm – Permalink

    It’s all about HTML about comment formatting. A good guide to follow. Thanks.

  6. User's Gravatar
    Rzym January 20, 2012 at 12:52 am – Permalink

    Very useful tip, thank you for this!

  7. User's Gravatar
    abogados April 1, 2012 at 2:33 am – Permalink

    Sorry, but I always make a little mess with this, do you refer to or. com? that maybe it is a very basic question but I do big messes.

    • User's Gravatar
      OddOneOut April 1, 2012 at 9:51 pm – Permalink, definitely :).

  8. User's Gravatar
    Florene February 9, 2015 at 9:50 pm – Permalink

    I blog often and I seriously appreciate your information. Your article has truly peaked my interest.

    I’m going to book mark your blog and keep checking
    for new details about once a week. I opted in for your RSS feed too.

Speak Up Your Mind!

An asterisk (*) indicates a required field and must be filled.

  • Web page and e-mail addresses turn into links automatically.
  • Wrap codes in: <code lang=""></code> or <pre lang="" extra="">
  • Lines and paragraphs break automatically.

Next Post: