• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / twenty_twenty_one_post_thumbnail() – Displays an optional post thumbnail.

You appear to be a bot. Output may be restricted

Description

Displays an optional post thumbnail.

Wraps the post thumbnail in an anchor element on index views, or a div element when on single views.

Usage

$void = twenty_twenty_one_post_thumbnail();

Parameters

Returns

void

Source

File name: twentytwentyone/inc/template-tags.php


Lines:

1 to 34 of 34
  function twenty_twenty_one_post_thumbnail() {
    if ( ! twenty_twenty_one_can_show_post_thumbnail() ) {
      return;
    }
    ?>

		<?php if ( is_singular() ) : ?>

			<figure class="post-thumbnail">
				<?php
        // Lazy-loading attributes should be skipped for thumbnails since they are immediately in the viewport.
        the_post_thumbnail( 'post-thumbnail', array( 'loading' => false ) );
        ?>
				<?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
					<figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
				<?php endif; ?>
			</figure><!-- .post-thumbnail -->

		<?php else : ?>

			<figure class="post-thumbnail">
				<a class="post-thumbnail-inner alignwide" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
					<?php the_post_thumbnail( 'post-thumbnail' ); ?>
				</a>
				<?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
					<figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
				<?php endif; ?>
			</figure><!-- .post-thumbnail -->

		<?php endif; ?>
		<?php
  }
 

 View on GitHub View on Trac

Published: 9th December 2020 | Last updated: 2nd November 2022

Primary Sidebar

Information

Function name: twenty_twenty_one_post_thumbnail
Plugin ref: Twenty Twenty-One
Version: 1.7
Sourcefile: inc/template-tags.php
File ref: inc/template-tags.php
Deprecated?: No
API Letters: O,P,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites