WordPress.org

Forums

How to remove HTML tags in WP comments (5 posts)

  1. Sven D.
    Member
    Posted 2 years ago #

    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?

  2. catacaustic
    very awesome
    Posted 2 years ago #

    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.

  3. Sven D.
    Member
    Posted 2 years ago #

    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.

  4. catacaustic
    very awesome
    Posted 2 years ago #

    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.

  5. Sven D.
    Member
    Posted 2 years ago #

    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 ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.