0

I've been researching for the past few hours, trying to find a way to disable HTML in WordPress comments. So far this one consistently appeared on top of Google search results numerous times:

// 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; 

This code did not work with the latest version of WordPress. I also found many more codes that again, did not work. So how would one go about disabling HTML in WordPress 3.6 (the latest version) comments?

3
  • How old are the articles you've found that code on? Commented Aug 11, 2013 at 3:31
  • Has the WordPress API changed in the meantime? Commented Aug 11, 2013 at 3:33
  • @Cole"Cole9"Johnson not sure but i found a solution to this problem :) Commented Aug 11, 2013 at 3:36

2 Answers 2

4

This removed the ability for users to post HTML (but not links for some strange reason) within comments:

add_filter( 'pre_comment_content', 'wp_specialchars' );

This removed the ability for users to post links within comments:

remove_filter('comment_text', 'make_clickable', 9);

Sign up to request clarification or add additional context in comments.

3 Comments

add_filter( 'pre_comment_content', 'wp_filter_nohtml_kses' ); has got links covered too.
And you add add_filter('get_comment_author_link', array('Comments_Cleaner', 'RemoveHTML')); and no spammer will spam you with links :)
This answer disables HTML by replacing HTML code with plaintext. Whereas the answer by Jothi disables HTML by removing the HTML code (e.g. <b>hello</b> becomes hello).
4

To disable HTML tags in comments, put the following code into your theme's functions.php:

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'); 

2 Comments

This is not what I want to do, I just wanted to disable them from COMMENTS not my whole website in general.
This code disables HTML by removing the HTML code (e.g. <b>hello</b> becomes hello). The answer by Dyck disables HTML by replacing HTML code with plaintext.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.