In this code snippet we will share how to allow image HTML tags in WordPress Comments. If you want to allow image HTML tags in comments, You need to add some line of code to theme’s functions.php file.

By hooking into the wp_kses_allowed_html filter, you have full control over what HTML is allowed to be displayed in post and comment content.

Add the following code to functions.php file:

<?php
//Allow image tags in comments
add_filter( 'wp_kses_allowed_html', array( $this, 'my_kses_allowed_html_hook' ), 20, 2 );
function my_kses_allowed_html_hook( $tags, $context = null ){
	if ( 'post' == $context && ! isset( $tags['img'] ) ) {
		$tags['img'] = array(
			'src' => 1,
			'height' => 1,
			'width' => 1,
			'alt' => 1,
			'title' => 1
		);
	}
	
	return $tags;
}
?>

If you feel this snippet useful? Any questions or suggestions? Do let me know your thoughts via comments.

How to Allow Image HTML tags in WordPress Comments Click To Tweet Don't forget to subscribe via email so you never miss a post! You can also follow us on Facebook and Twitter!
How to Allow Image HTML tags in WordPress Comments
5 (100%) 3 votes

(Visited 87 times, 1 visits today)

About the Author: Editorial Staff

Editorial Staff at the WPChandra is a team of WordPress experts writing about WordPress Tutorials, Themes, Plugins, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *