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') );
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected]com. Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners, wpbeginner, wpbeginner tutorial, wpbeginners