Support » Plugins » Hacks » How to remove HTML tags in WP comments

  • Hi

    How do I remove/disallow a HTML tag in comments (from the functions-file)?

    For example: < strong > is allowed as standard in WordPress, but I would like to disallow it. I guess that it is possible to hook in via add_action(‘comment_post’

    Do you have a soultion?

Viewing 4 replies - 1 through 4 (of 4 total)
  • One thing that will work is:

    add_filter ("comment_text ", "my_filter_function");
    function my_filter_function ($content) {
        return strip_tags ($content);

    That will remove all HTML tags from the comment text before it’s displayed on the site. Please note that it doesn’t remove the tags from what’s submitted or stored in your DB, it jsut keeps things clean on the public-facing side of your site.

    Thank you very much for your suggestion, catacaustic 🙂

    The “problem” is this: when I upgrade WordPress I edit the kses.php to fit my needs; removing some allowed tags and add some. Editing WPs core files is never a good idea, so I hoped there was a way to do this via a php snippet in the functions.php file.

    Have a look at the function that does what you are looking for in the kses.php file and see if there’s any calls to do_filter(). If there is take note of the filter that’s being called and set up your own filter in your functions.php file. If there’s no filters there you could try and go through the process tree to find out where things come after this and see if there’s any filters available further down the track, but that’s going to be hard going.

    Thanks again, catacaustic 🙂

    I will digg a little more into it and see if I can find a solution. Was hoping that someone else already had a solution to it 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to remove HTML tags in WP comments’ is closed to new replies.