disable html code in comments wordpress

disable html code in comments wordpress

WordPress tutorial for, disable html code in comments wordpress. We given code sample for functions file to prevent html code in wordpress comments section.

If you are wordpress developer then only use following code. Open your functions.php file from your theme and put following code in that file. Just copy and paste the following code on your functions.php file:

disable html code in comments wordpress

function wordpress_comment_post( $incoming_comment ) {
	$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
	$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
	return( $incoming_comment );
}

function wordpress_comment_display( $comment_to_display ) {
	$comment_to_display = str_replace( ''', "'", $comment_to_display );
	return $comment_to_display;
}
add_filter( 'preprocess_comment', 'wordpress_comment_post', '', 1);
add_filter( 'comment_text', 'wordpress_comment_display', '', 1);
add_filter( 'comment_text_rss', 'wordpress_comment_display', '', 1);
add_filter( 'comment_excerpt', 'wordpress_comment_display', '', 1);
disable html code in comments wordpress
disable html code in comments wordpress

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “disable html code in comments wordpress”

Leave a Reply

Your email address will not be published.