WordPress: Change Allowed Comments Html Tags [ allowed_tags() ]

Your blog readers can post comments with the html tags. You can display a list of all allowed HTML tags in the comments form using the following php code. Open comments.php (located in your themes directory) file and append the following code either before the comment form or submit button html code (please note that some themes have the following code, but it is usually commented out).

Your blog readers can post comments with the html tags. You can display a list of all allowed HTML tags in the comments form using the following php code. Open comments.php (located in your themes directory) file and append the following code either before the comment form or submit button html code (please note that some themes have the following code, but it is usually commented out).

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

Change Allowed HTML Tags

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' =&gt; array(),
      'em' =&gt; array(),
      'pre' =&gt; array(),
      'code' =&gt; array(),
      'a' =&gt; array(
        'href' =&gt; array (),
        'title' =&gt; array ())
  );
 
  $allowedtags = array(
      'strong' =&gt; array(),
      'em' =&gt; array(),
      'pre' =&gt; array(),
      'code' =&gt; array(),
      'a' =&gt; array(
        'href' =&gt; array (),
        'title' =&gt; array ())
  );
}
</a></em></strong>

Save and close the file.

A Note About Thesis Theme

If you are using thesis theme add the following code in custom/custome_functions.php file:

Save and close the file. Make sure you clear cache by visiting supercache or wp-cache setup page.

Author: admin

I like chocolate, gadgets, open source software, photography, traveling and all shades of green colors. I love spending time with fun loving friends and family members. This is my own online journal.

15 thoughts on “WordPress: Change Allowed Comments Html Tags [ allowed_tags() ]”

  1. thank you very much, thanks to the article above insights and information I became more widespread

  2. This is a really nice post which is filled with great stuff. surely will share with mates for sure.

Leave a Reply to Dan

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