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="https://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="https://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="https://wordpress.stackexchange.com/questions/155438/mywordpressdomain/image.jpg"><img src="https://wordpress.stackexchange.com/questions/155438/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="https://wordpress.stackexchange.com/questions/155438/mywordpressdomain/image.jpg"><img src="https://wordpress.stackexchange.com/questions/155438/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);