Wordpress <?php the_post_thumbnail( 'full' ); ?> without the img-tag

前端 未结 2 941
猫巷女王i
猫巷女王i 2021-01-12 07:12

I have noticed that using the post_thumbnail() function in Wordpress inserts the image including the img-tag. Is there a way to have it insert ONLY the src of that image?

2条回答
  •  情深已故
    2021-01-12 07:56

    Post Thumbnail Linking to large Image Size This example links to the “large” Post Thumbnail image size and must be used within The Loop.

    if ( has_post_thumbnail() ) {
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
    if ( ! empty( $large_image_url[0] ) ) {
        echo '';
        echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); 
        echo '';
    }}
    

    Source : https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

提交回复
热议问题