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.

wordpress-hacks

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.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Solved Programs