Support » How-To and Troubleshooting » [Resolved] Disabling HTML tags in comments

[Resolved] Disabling HTML tags in comments

  • I hacked the kses.php and added // before the undesired HTML tags in the variable $allowedtags. However when I tried posting:

    <b>Test comment</b>

    the “Test commment” is bolded.

    Why doesn’t it work?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plonk this in your theme’s functions.php file.

    Eg. wp-content/your-theme/functions.php

    add_filter( 'comment_text', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_text_rss', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_excerpt', 'wp_filter_nohtml_kses' );

    After the opening PHP tag, ie. <?php …so it looks like this..

    add_filter( 'comment_text', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_text_rss', 'wp_filter_nohtml_kses' );
    add_filter( 'comment_excerpt', 'wp_filter_nohtml_kses' );

    I get this:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wp_filter_normal_kses’ not found or invalid function name in E:\Software\xampp\htdocs\wordpress\wp-includes\plugin.php on line 166

    Any plugins currently active?

    No, except the default ones. I’ll try again, sometimes a couple days’ rest helps speed things up 🙂

    I’ve tested the code in two installations, one running 2.9.2 and another running the latest SVN of 3.0, it worked without errors in both cases.

    Perhaps it would help to paste your complete functions.php into a pastebin so i can see how you’ve pasted the code and where..

    Okay now here’s the weird thing:

    After adding the 3 lines of add_filter(); it works, no errors whatsoever, but in my kses.php I did not have the <b> tag commented out but yet the comment is not bolded.

    Well yeah all tags will be stripped out, that’s what you asked for..

    Disabling HTML tags in comments

    If you want to limit the tags available you’d need a different solution, i assumed from the title you wanted all tags stripped.

    Oh sorry for the unclear title. What I wanted was to disable certain tags, but not all.

    I followed this solution: http://codex.wordpress.org/Answers-Configuration#Stopping_HTML_in_Comments but it doesn’t work.

    The approach does work, just ensure you edit the $allowedtags array, not the preceeding $allowedposttags array which is for posts.

    It doesn’t for me :X

    Just checking, that approach doesn’t require any adding of lines to the functions file, right?

    So you’re editting kses.php as indicated on the above link right?

    If won’t strip any existing comments if that’s what you’re expecting, once the changes are made it will only effect new comments being posted. Dealing with existing comments would require a different approach.

    I was just about to post that it didn’t work, new comments with the commented-out-tags still appear as if the tags were working. Then I had a thought and realized that the moderation only applies to “visitors”. I, as the admin, can post comments with the disallowed tags :X



    This is exactly what I was looking for. Just a small note, Firefox seems to still show HTML formatting and hyperlinks in the RSS feed; comments on site are OK, and viewing in IE the comments in RSS feed are OK too. I’m not sure why Firefox is different.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] Disabling HTML tags in comments’ is closed to new replies.