How to get WordPress post featured image URL

前端 未结 20 1900
闹比i
闹比i 2020-12-02 04:59

I am using this function to get the featured images:


    


        
相关标签:
20条回答
  • 2020-12-02 05:20

    I think this is the easiest solution and the updated one:

    <?php the_post_thumbnail('single-post-thumbnail'); ?>
    
    0 讨论(0)
  • 2020-12-02 05:20

    This is the simplest answer:

    <?php
        $img = get_the_post_thumbnail_url($postID, 'post-thumbnail');
    ?>
    
    0 讨论(0)
  • 2020-12-02 05:20

    Use:

    <?php 
        $image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail_size');
    
        $feature_image_url = $image_src[0]; 
    ?>
    

    You can change the thumbnail_size value as per your required size.

    0 讨论(0)
  • 2020-12-02 05:20

    You can also get the URL for image attachments as follows:

    <?php
        "<div><a href=".get_permalink(id).">".wp_get_attachment_url(304, array(50,50), 1)."</a></div>";
    ?>
    
    0 讨论(0)
  • 2020-12-02 05:24
    <img src="<?php echo get_post_meta($post->ID, "mabp_thumbnail_url", true); ?>" alt="<?php the_title(); ?>" width ="100%" height ="" />
    
    0 讨论(0)
  • 2020-12-02 05:26

    I had searched a lot and found nothing, until I got this:

    <?php echo get_the_post_thumbnail_url( null, 'full' ); ?>

    Which simply give you the full image URL without the entire <img> tag.

    Hope that can help you.

    0 讨论(0)
提交回复
热议问题