By: Prem Tiwari | Last Updated:
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
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.
//add custom attributes in image
the_post_thumbnail( 'thumbnail', array('class'=>;'img-responsive') );
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari