[post_featured_image]

The shortcode displays the featured image of a post, page, or custom post type in various formats.


Product


Shortcode Attributes

  1. id – Post ID whose featured image you want to display.
    • Options: Any valid post ID.
  2. return – Determines the format of the output.
    • Default: img.
    • Options: img or url.
  3. size – The size of the featured image.
    • Default: full.
    • Options: full, thumbnail, medium.
  4. placeholder – Specifies a placeholder image if no featured image is found.
    • Options: avatar, empty, or a custom URL.
  5. label – A label above the featured image.
    • Options: Any text value.

Shortcode Enclosed Content

Any content placed between [post_featured_image] and [/post_featured_image] will be used as a template, where {content} acts as a placeholder for the featured image.


Example Usage

Example 1

[post_featured_image]

Results

<img class="attachment-full size-full wp-post-image" fetchpriority="high" decoding="async" width="1920" height="1280" src="https://yoursite.com/wp-content/uploads/2023/06/featured-image.jpg" alt="" srcset="https://yoursite.com/wp-content/uploads/2023/06/featured-image.jpg 1920w, https://yoursite.com/wp-content/uploads/2023/06/featured-image-800x533.jpg 800w, https://yoursite.com/wp-content/uploads/2023/06/featured-image-1200x800.jpg 1200w, https://yoursite.com/wp-content/uploads/2023/06/featured-image-768x512.jpg 768w, https://yoursite.com/wp-content/uploads/2023/06/featured-image-1536x1024.jpg 1536w" sizes="(max-width: 1920px) 100vw, 1920px">
This example returned the featured image of the current post/page as an HTML <img> tagю
If no ID is provided, the shortcode will automatically use the ID of the current post/page.
If the post type is location_post or location_page, the shortcode will retrieve the featured image of the linked location.
The shortcode supports lazy loading for images by default.

Example 2

[post_featured_image id="123" placeholder="https://example.com/custom-placeholder.jpg"]

Results

This example returned the featured image of the post with ID 123. If no featured image is found, the custom placeholder image will be displayed.

Example 3:

[post_featured_image return="url" label="Featured Image"]

Results

<label>Featured Image</label>
https://yoursite.com/wp-content/uploads/2023/07/featured-image.jpg
This example returned the URL of the featured image instead of an HTML <img> tag and textFeatured Image above the featured image.