Add HTML Tags and Attributes back into Comments in WordPress

Since WordPress 3, the notice of being able to use HTML Tags and Attributes has been removed and there is just an empty string, which means that the use of the allowed tags in comments is still feasible but readers may not know. You can add this notice back in using the filter comment_form_defaults

wordpress-filter-comments-html-tags

Add in your themes functions.php file

You can use the filter to change many elements either text strings or markup, below is a list…

So if you wanted to add the tags and change the label_submit text to ‘Post A Reply‘ you can adjust the earlier function wpb_comments_change() like so…

Modifying the Allowed Tags for Comments

So these allowed HTML tags are generated from the allowed_tags() function which stores the tags in /wp-icludes/kses.php as a global array variable $allowedtags –  you could set what tags you want by redefining the variable $allowedtags

Here I have taken a bunch of tags out and added pre in, this works, however it is advised against in kses.php  and you are advised to use wp_kses_allowed_html() (but this edit works ok for my purpose).

So the user would see…

wordpress-filter-comments-html-tags-edited

 

7 Comments

  1. Sarah Hall on January 20, 2023 at 5:58 am

    Thank you! Still useful in 2023

  2. Famdam Dizzle on June 5, 2021 at 7:53 am

    Is your website implying wpbitches? Lol ?

  3. Nur Hossain on November 6, 2020 at 4:42 pm

    Thanks to give this information. It helps me a lot………………..

  4. berita otomotif motor on November 2, 2019 at 3:48 pm

    thanks bro..

  5. david on May 4, 2016 at 4:44 am

    Thank you

  6. Aliza on January 20, 2016 at 1:15 pm

    THankyou working…..

    • Mark Sandel on July 25, 2016 at 1:34 pm

      True, a good article!

Leave all Comment