简体   繁体   中英

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

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?

Sofar i have tried this

$image = get_the_post_thumbnail( $post->ID, 'thumbnail' ); echo $image;

but it just exports the same. Any ideas? thanks in advance for your help :)

Found answer. Thanks anyway.

<?php
//Get the Thumbnail URL
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(320,240), false, '' );
echo $src[0];
?>

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 '<a href="' . esc_url( $large_image_url[0] ) . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
    echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); 
    echo '</a>';
}}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM