2025-03-24 05:29:01
WordPress allows the use of certain HTML tags in the comments section, such as <a>, <em>, and <strong>, which can be beneficial to commenters. However, on the other hand, they are often exploited by spammers.
Spam comments often contain HTML links and bold text to promote unwanted content, which are frequently generated by bots, filling your website with undesirable material.
Fortunately, you can easily disable HTML in WordPress comments, which will help reduce spam and make the discussion area cleaner and safer.
Enabling HTML in comments allows users to format their text, but it also opens the door to abuse, such as using bots to post inappropriate messages or create potentially harmful links.
Disabling HTML makes comments with tags, such as:
Still displayed, but HTML tags will no longer have any effect, which will help keep the content in your comments section safe and orderly.
Normally, disabling HTML in comments requires adding code to the theme's functions.php file, which can be complex and risky, potentially breaking the website if done incorrectly. Therefore, we recommend using the WPCode plugin for safety and ease of management.
How to use WPCode to disable HTML in comments
add_filter( 'preprocess_comment', function( $incoming_comment ) {
$incoming_comment['comment_content'] = htmlspecialchars( $incoming_comment['comment_content'] );
$incoming_comment['comment_content'] = str_replace( "'", '', $incoming_comment['comment_content'] );
devolver $incoming_comment;
});
add_filter( 'comment_text', function( $comment_to_display ) {
$comment_to_display = str_replace( '', "'", $comment_to_display );
return $comment_to_display;
});
You can try commenting on your website using HTML tags and see the result where the text still appears, but the HTML tags won't work.
Note: This method is beginner-friendly and does not require editing the core WordPress files.
WordPress automatically converts URLs typed in comments into links, which can be a potential source of spam. If you want to disable this feature for added security, you can easily use WPCode to add custom code.
If you want to know how to do it in detail, you can check our guide on disabling automatic links in WordPress comments.
Disabling HTML in WordPress comments is an effective way to reduce spam and make your website more secure. With the WPCode plugin, you can easily set it up without having to modify the core WordPress system files.
I hope this article is helpful, and if you want to further improve the comment system, don't forget to explore plugins that enhance functionality for WordPress and learn how to display the most commented posts on your website.
2025-01-10 10:12:01
2024-05-31 03:06:49
2024-05-28 03:09:25
There are many other interesting articles, try selecting them from below.
2023-09-07 10:30:37
2024-11-06 11:31:16
2023-11-13 10:19:00
2024-12-03 01:14:34
2024-04-19 03:03:34
2024-05-02 10:07:23
2023-10-20 09:31:28
2024-06-06 02:05:04