wp_get_attachment_caption example


function get_the_post_thumbnail_caption( $post = null ) {
    $post_thumbnail_id = get_post_thumbnail_id( $post );

    if ( ! $post_thumbnail_id ) {
        return '';
    }

    $caption = wp_get_attachment_caption( $post_thumbnail_id );

    if ( ! $caption ) {
        $caption = '';
    }

    return $caption;
}

/** * Displays the post thumbnail caption. * * @since 4.6.0 * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. */
                /** * Filter the default image attachment size. * * @since Twenty Twenty-One 1.0 * * @param string $image_size Image size. Default 'full'. */
                $image_size = apply_filters( 'twenty_twenty_one_attachment_size', 'full' );
                echo wp_get_attachment_image( get_the_ID()$image_size );
                ?> <?php if ( wp_get_attachment_caption() ) : ?> <figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption() ); ?></figcaption> <?php endif; ?> </figure><!-- .wp-block-image --> <?php             the_content();

            wp_link_pages(
                array(
                    'before'   => '<nav class="page-links" aria-label="' . esc_attr__( 'Page', 'twentytwentyone' ) . '">',
                    'after'    => '</nav>',
                    
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() ) ) : ?>
Home | Imprint | This part of the site doesn't use cookies.