Home / template / Add custom attribute to image using the_post_thumbnail
  • How to Add custom attribute to image using the_post_thumbnail

    add-custom-attribute-to-image-using-the_post_thumbnail

    Sometimes you will need to add a custom attribute to an image. This is very easy to do using the_post_thumbnail() function. The following snippet will add the custom attribute of 'itemprop="image" to your images but you can change that to nearly anything including class, alt, title etc.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    the_post_thumbnail( 'thumbnail', array('itemprop'=>'image') );
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_post,