The following code will show the featured image or thumbnail of a post or page.

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'full' );
}

Substitute “full” with the desired thumbnail size you would like to use. It can be medium, large or your own custom size.

If you would like to link to the image in a lightbox use the following code:

<a class="lightbox-popup" href="<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'large', true);echo $image_url[0]; ?>">
<span itemprop="image"><?php the_post_thumbnail('medium', array('class' => 'colorbox-1')); ?></span>
</a>

If you would like to add a class or id to the featured image use the following code



<?php the_post_thumbnail('medium', array('class' => 'custom-class')); ?>

The class in the above example is “custom-class”.

For a full list of capabilities with the featured image check out the WordPress codex here: https://codex.wordpress.org/Post_Thumbnails

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.