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

Disclosure: This post contains affiliate links. This means we may make a small commission if you make a purchase. This doesn’t cost you any more but it does help us to continue publishing helpful content – thank you for your support!

How to Allow Image HTML tags in WordPress Comments
5 (100%) 3 votes

(Visited 89 times, 1 visits today)

Leave a Comment

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