Request quote

How to remove HTML tags and links from wordpress comments?

Posted on: May 28th, 2013 by Webgalli No Comments

Seems many of the WordPress web masters are worried about the spam comments in their post discussion threads. We have implemented a simple technique to restrict the wordpress spam comments. Most of the time the spammers post some junk comments and a ink to their web pages. You can use the following code to restrict these spammers. Due to the lack of time, we are not planning to develop a WordPress plugin for this simple functionality. Just copy the following lines of code into the functions.php file of your active theme and this will restrict the spam comments to a certain extend.

How to remove all HTML tags.

This will block all the html tags inserted into the comments field like

function galli_spam_filter() {
	$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
		wp_die( __('<strong>ERROR</strong>: Please dont use html tags inside the comments.') );
add_action('pre_comment_on_post', 'galli_spam_filter');	

function galli_hasTags( $str ){
	return !(strcmp( $str, strip_tags($str ) ) == 0);

How to remove all the links on the comments field.

By default, WordPress make all the links in the comments data clickable. Adding the following line to the functions.php will remove this functionality and the links wont be clickable.

remove_filter('comment_text', 'make_clickable', 9); // Remove comments autolinks

There are many other comment spam blockig tools too for wordpress. They will also help you to limit the spams.

Tags: , , , , ,