How To Disable HTML In WordPress Comments
Read the post to learn how you can disable HTML in WordPress comments.
If you keep a WordPress website that allows users or visitors to comment on your post, you must have faced spamming. So many people leave a comment with links that leads to Spam.
Most of the spam comments are made by bots using HTML tags. WordPress allows some HTML tags within the comments such as <a> <em> <strong> etc. Users use HTML tags to style their comments such as making words bold, italic, or adding links to their comments.
If you disable HTML from your WordPress comments, it can prevent SPAM. So with no delay, let us tell you how you can do this.
However, using this, you can only remove active HTML tags. So someone can still post something with tags. It will show up, but the tags will not be functional.
Disable HTML in WordPress Comments By Using Plugins.
For disabling HTML in WordPress comments, you can try the plugin method.
1. Comment Link Remove plugin
You can easily disable HTML in WordPress comments by installing the Comment Link Remove plugin.
Login to your WordPress dashboard.
Go to Plugins>>New Plugin >>search Comment Link Remove plugin>>Install>>Activate
Now, After installing the plugin
Go to Settings >>click on QC CLR settings.
Enable the following options.
- Disable turning URL’s into hyperlinks in comments
- Remove HTML link tags in comments
Afterward, click on the Save button.
This will disable active HTML link tags in comments. If anyone adds the HTML tags in comments, it will show, but links will not function.
2. All-in-One Optimizer and Customizer
The next one is All-in-One Optimizer, and Customizer plugins have simple options to disable HTML from comments. Install and activate the plugin.
Check our step-wise guide on How to install WordPress plugin.
Now, After installing the plugin
- Go to AIO Optimizer >> WP-Admin Tweaks page.
- Enable toggle >>Disable HTML from Comment.
Disable HTML in WordPress Comments By Using code.
1. Our first coding is given below. You have to follow simple steps to remove HTML tags.
open your functions.php and paste the code given below:
// This will occur when the comment is posted 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; }
2. You can use another code. This will help in removing HTML in WordPress comments. But this will only disable active HTML tags.
place this code in your functions.php
<?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); ?>
To conclude, if you want to remove HTML in WordPress comments, you can use any of your favorite options. If you like coding, you can do it manually; otherwise, do it by plugins. We hope this has helped you.
You can also check our another post on how to display the most accurate comment on WordPress.