WordPress Tip: Remove All HTML Tags In Comments

WordPress Tip: Remove All HTML Tags In Comments

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 functions.php file:

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.

Using 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!

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO