By default, WordPress allows commentators to use some HTML tags in comments for links, quote or format text. But in many blogs, these tags are rarely used, or even they're used for spam links. In that case, we might want to let the commentators use only plain text in comments without any HTML tags.
To remove all HTML tags in comments, paste the following code into
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');
Here we apply WordPress built-in function
wp_filter_nohtml_kses to some filters, used to display comments. The function
wp_filter_nohtml_kses will strip all HTML tags in some string, in this case – comment.
wp_filter_nohtml_kses, we don't have to care about writing handy code for checking HTML tags using regular expressions (usually, it's a hard job). Because it's built-in WordPress core, it's really safe and fast!