A Guide to HTML Post Comments in WordPress

WordPress is great for blogs, and of course commenting is an essential part of blogging. Your blog readers can post comments with HTML tags. For their convenience, you can display a list of all allowed HTML tags in the comments form using the following PHP code in functions.php:

Allowed tags: <?php echo allowed_tags(); ?>

Change Allowed HTML Tags

You can also change what HTML tags are allowed in your comments form.

Edit functions.php (located in your wp-content/themes/ directory) and append the following code:


/*
*  only allow <strong>, <em>, pre, code, and <a href=""> tags
*/
add_action('init', 'my_html_tags_code', 10);
function my_html_tags_code() {
  define('CUSTOM_TAGS', true);
  global $allowedposttags, $allowedtags;
  $allowedposttags = array(
      'strong' => array(),
      'em' => array(),
      'pre' => array(),
      'code' => array(),
      'a' => array(
        'href' => array (),
        'title' => array ())
  );

  $allowedtags = array(
      'strong' => array(),
      'em' => array(),
      'pre' => array(),
      'code' => array(),
      'a' => array(
        'href' => array (),
        'title' => array ())
  );
}

If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.

About Jean Galea

Jean Galea is a WordPress developer, trainer and consultant. He is the founder of WP Mayor and is available for freelance work. You can get in touch via his website at www.jeangalea.com.

More from the Mayor:

  1. A Guide to WordPress Post Formats
  2. Extract All Image Sources from a WordPress Post
  3. The Ultimate Guide to WordPress Custom Post Types
  4. The Ultimate Guide to WordPress 3 Menus
  5. Getting Started With HTML 5 and WordPress

3 Responses

  1. taper roller bearing
    taper roller bearing February 16, 2012 at 03:36 | | Reply

    ok,very goog thank you

  2. santa
    santa March 10, 2012 at 14:16 | | Reply

    Great blog.

  3. html color name
    html color name April 4, 2012 at 19:54 | | Reply

    great tutorrials are shared thanks for this
    html color name

Leave a Reply