How to Add Unique Image Class in WordPress

If you want to dynamically add your own class to every image added from WordPress Editor then use following code. Add the code into your theme’s functions.php file and change the class according to your requirement.

function wphe_image_class_filter($classes) {
	return $classes . ' your_class_name_here'; //make sure to add a space in front of the class name
}
add_filter('get_image_tag_class', 'wphe_image_class_filter');

Leave a Reply

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