When I'm in the Wordpress editor and I add an external image with the 'img' button, my html result wil be like this:
<img src="http://example.com/image.jpg" alt="image" />
How can automatically have a class being added to the img tag? Like this:
<img class="my-img-class" src="http://example.com/image.jpg" alt="image" />
I would like to apply the same principle to the 'Add Media' option. This output is like this:
<a href="mywordpressdomain/image.jpg"><img src="mywordpressdomain/image.jpg" alt="image" width="872" height="867" class="alignnone size-full wp-image-59" /></a>
And I want the output to be like this:
<a href="mywordpressdomain/image.jpg"><img src="mywordpressdomain/image.jpg" alt="image" width="872" height="867" class="alignnone size-full my-img-class" /></a>
I'm new with PHP, so I'm not sure how to this via a filter. I'm started like this, but I don't know what to do next:
function image_tag_class($class, $id, $align, $size) {
return $align;
}
add_filter('get_image_tag_class', 'image_tag_class', 0, 4);