Home / css / Add a Class to ‘the_post_thumbnail’ a Featured Image
  • How to Add a Class to ‘the_post_thumbnail’ a Featured Image

    add-a-class-to-the_post_thumbnail-a-featured-image

    When adding a featured image to a template, you may want to add a class to the image tag that is being generated. This extra class will allow you to use CSS to format it better.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    if ( has_post_thumbnail() ) {
      the_post_thumbnail('medium', array('class' => 'alignleft'));
    }
    

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

    the_post, has_post_thumbnail,
  • Tobi

    Thx a lot!! This is what I was lokking for!!

  • Tobi

    Thx a lot!! This is what I was looking for!!

  • aleksiejs

    Thank you 😉 I was looking for it 😉

    Happy new year!

  • saved my day!!! Thank you