How To Disable HTML Tags and links In WordPress Comments?
If you’re are running a WordPress Site and allowing your visitors to comment on your articles, you have surly faced the problem of spamming on your blog post. By default setting of WordPress allow user to able to use some HTML tags to style their comments.
User can comment HTML tag to make words bold, italic or they will add links into your comments.
If you observe a lot of SPAM comments comes on your article that may contain these tags. Mostly spam comments are generated via bots and scripts, which contenting HTML tags with links and script. This comments are not relevant to your article and doesn’t make any sense.
You can solve this issue by disabling HTML Tags In WordPress Comments. Here i am showing you the way How you can Disable HTML Tags In WordPress Comments.
Solution 1:
Add following snippet to your theme’s functions.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php function plc_comment_post( $incoming_comment ) { // convert everything in a comment to display literally $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']); // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] ); return( $incoming_comment ); } // This will occur before a comment is displayed function plc_comment_display( $comment_to_display ) { // Put the single quotes back in $comment_to_display = str_replace( ''', "'", $comment_to_display ); return $comment_to_display; } add_filter( 'preprocess_comment', 'plc_comment_post', '', 1); add_filter( 'comment_text', 'plc_comment_display', '', 1); add_filter( 'comment_text_rss', 'plc_comment_display', '', 1); add_filter( 'comment_excerpt', 'plc_comment_display', '', 1); ?> |
Solution 2:
- Open functions.php file
- Copy and paste the following snippet:
1 2 3 |
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'); |
This above 2 code snippets will only disable HTML tags. So someone you are able to post special char like :
< a> < em> < strong>
Solution 3:
If you want to remove only link tag from comment data, and allow other tag like b, span, etc than you can use this code snippets.
This removed the ability for users to post links within comments:
1 |
remove_filter('comment_text', 'make_clickable', 9); |
Conclusion
I hope the above solution definitely works for you, and if you find any query or have the way other than this then do share it in the comment section. And please share your thoughts about the post and how much you find it helpful to you. 🙂
[paypal-donation]