Add more HTML tags in WordPress comments

If you don’t want your visitors to be able to use HTML tags in their comments, you can easily destroy all of their efforts. If you don’t want them to be able to post active hyperlinks, you can add more salt to their wound. But what if you’re a nice guy and want to give even more power to the people who spend their time writing those awesome comments under your posts?

Well, then you should give them more HTML tags to play around with, of course.

After you go through this article, you won’t be limiting your commenters, but you will give them more tags to work with. And you will do that through some custom coding. Don’t worry; we will give you the basic code which you have to copy and paste, as usual, and you will be choosing which tags to allow in your comments.

HTML tags in WordPress comments

Add more HTML tags in comments:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. function allow_pres() {
    global $allowedtags;
    $allowedtags['pre'] = array('class'=>array());
    add_action('comment_post', 'allow_pres');
  4. Save changes

The first function will tell WordPress that you’re benevolent man – you give more tags to a wider audience, isn’t that great? The other one simply adds the hook which will use that functions when needed.

So far, the code adds <pre> tag in the “allowed tags” bucket. Here comes your part of coding. You can add any number of tags into the function.

Add extra tags:

To add extra tags, use the following line:

  • $allowedtags[‘p’] = array();

For each tag, repeat the entire line of code and change the tag itself. For example:

  • $allowedtags[‘b’] = array();
  • $allowedtags[‘i’] = array();
  • $allowedtags[‘u’] = array();

If you want to go more into detail, you can use the class key as shown in the original code above. The class key allows you to specify allowed attributes to the tag as well.

If you’re not sure which tags you want to be active in your comments, go through a list of HTML tags.


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

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