How to Add custom attribute to image in WordPress

In today’s tutorial, I will explain “How to Add a custom attribute to the image in WordPress“. This is very useful for all WordPress developers. Sometimes while you are developing a WordPress based website, then you need to add a custom attribute like class, alt, title, id, and etc to an image using the_post_thumbnail() function.


If you have just started with WordPress, then check out:

Below function will add the custom attributes in your image field. In the below example, I have added ‘class’=>’img-responsive’ extra attribute using the_post_thumbnail function. You can use the below function your theme and plugin files where it required.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , , , , , ,