Get featured image url wordpress

New Page

How to Get Featured Image URL in WordPress (2 Easy Ways)

byHamza Afridi

How to Get Featured Image URL in WordPress

Featured images are a great way to make your content more engaging. Adding a featured image to WordPress posts can significantly improve the readability of your content. Featured images can be used for blog posts, pages, and custom post types.

If he is a WordPress developer and creates themes and addons from scratch or even modifies existing themes and addons to include featured images on pages, posts or custom posts, then how do you get the ‘Featured image URL in WordPress is something he’ll really care about. want to know.

In this guide, I will show how you can get a featured image URL in WordPress.

Note: First, make sure your WordPress theme supports featured images.

Contents

  • Enable featured image support with Php code
  • Get highlighted image URL with Inspect Item
  • Get Featured Image URL With Php Code
  • Frequently Asked Questions (How to Get Featured Image URL in WordPress)
    • How to find the URL of a featured image in WordPress?
  • Conclusion

Enable featured image support with Php code

Most themes already have featured images enabled, but if you are developing a theme from scratch or your current theme does not have this feature enabled, insert this code into function.php.

<?php

// Enable theme support for featured images

add_theme_support(‘post-thumbnails’);

? >

<?php //Enable theme support for selected images add_theme_support(‘post-thumbnails’); ?>

<?php //Enable theme support for selected images add_theme_support(‘post-thumbnails’); ?>

Note: the function.php file can be found in Appearance > Theme Editor > then, at the top right of the screen, locate the function.php file

Therefore, if your theme does not include the post thumbnail feature, you will not be able to add a featured image when editing a post.

How to Get Featured Image URL in WordPress

As you can see, there is no option available to add a featured image to the post.

but after adding above code in function.php file, it will be able to add featured image to post

Show featured image option

Ahora que ha habilitado la compatibilidad con la détacada image, lo siguiente que tiene en minte es cómo get la URL de la détacada image. Así que demostraré dos forms de fetch the URL of the deleted image.

Te podría gustar:

How to disable the automatic collection of stored images in WordPress

How to hide the deleted image in the WordPress publication

Obtenga la URL de la imagen destacada con Inspeccionar elemento

Para obtener la URL de la imagen destacada (miniatura) de una publicación o página, ubique cualquiera de las publicaciones o páginas en su sitio web y haga clic derecho en la imagen destacada (miniatura) y haga clic en ‘inspeccionar elemento’.

So, on the right side of your screen in developer tools, you  will see the URL of the featured image

Get highlighted image url with inspect element

Cependant, vous pouvez également obtenir l’URL de l’image en vedette en cliquant avec le bouton droit sur l’image en vedette (vignette) sur n’importe quel article, puis en cliquant sur l’adresse de l’image de copie.

Ainsi, l’URL de l’image en vedette est maintenant copiée dans votre presse-papiers

How To Get Featured Image URL In WordPress Get Featured Image URL With Php Code

WordPress has its built-in get_the_post_thumbnail() function to display featured images for posts, pages, and attachments based on various parameters like height, id, width, etc.

<?php

//Display the selected image in an <img> tag (use this in a loop)

echo get_the_post_thumbnail();

? >

<?php //Display the selected image in an <img> tag (use this in a loop) echo get_the_post_thumbnail(); ?>

<?php //Display the selected image in an <img> tag (use this in a loop) echo get_the_post_thumbnail(); ?>

This is the easiest approach to displaying a post’s featured image in the famous WordPress loop.

If you want the function to display the thumbnail (selected image) of the current post, you add this parameter in get_the_post_thumbnail().

<?php

echo get_the_post_thumbnail($post_id);

? >

<?php echo get_the_post_thumbnail( $post_id ); ?>

<?php echo get_the_post_thumbnail( $post_id ); ?>

you can also adjust the size of thumbnails (featured images) by giving a second size argument in the code above,

<?php

echo get_the_post_thumbnail($post_id, “medium”);

? >

<?php echo get_the_post_thumbnail( $post_id, “medium”); ?>

<?php echo get_the_post_thumbnail( $post_id, “medium”); ?>

Remarque : vous pouvez donner différentes tailles comme deuxième argument comme moyen, grand ou complet (taille d’origine).

Maintenant, vous pouvez utiliser la fonction get_the_post_thumbnail_url() pour renvoyer l’URL de l’image sélectionnée.

< ?php

//Affiche l’URL de la publication en vedette (vous pouvez remplacer “moyen” par une taille d’image différente)

echo get_the_post_thumbnail_url($post_id, “moyen”);

? >

<?php //Affiche l’URL de l’article en vedette (vous pouvez remplacer ‘moyen’ par une taille d’image différente) echo get_the_post_thumbnail_url( $post_id, “medium”); ?>

<?php //Display the URL of the featured post (you can replace ‘medium’ with a different image size) echo get_the_post_thumbnail_url( $post_id, “medium”); ?>

So with this code, you can get the featured image URL of a post. You can use this code with WordPress loop or anywhere else that requires post thumbnail functionality. If you want to dig deep into how the get_the_post_thumbnail() function works, you can read it here.

FAQ(How To Get Featured Image URL in WordPress)

How do I find the URL of a featured image in WordPress?

get_the_post_thumbnail_url() is a built-in WordPress function that returns the URL of the featured image for a post or a page. However, if you want to save this address, you’ll need to create a variable for it.

$featured_img_url = get_the_post_thumbnail_url($post_id)

Hence the URL is now stored in that variable and you can use it anywhere you want

Conclusion

As you can see, getting the featured image URL in WordPress is quite simple and straightforward. I explained different methods to get featured image URL in WordPress. These methods should work regardless of the theme, because that’s how you get images from the WordPress database.

Hope this article helps you to get featured image URL. If you have any questions or clarifications, feel free to ask them in the comment section below.

Categories How to post a navigation

How to Change Profile Picture in WordPress without Gravatar

How to Embed an iFrame Code in WordPress (3 Easy Ways)

Skip to content

  • Connexion
  • S’inscrire

WordPress.org

  • Nouvelles
  • Télécharger et étendre
    • Obtenez WordPress
    • Thèmes
    • Motifs
    • Plugins
    • Openverse
    • Mobile
    • Hébergement
  • Apprendre
    • Apprendre WordPress
    • Soutien
    • Forums
    • WordPress.tv
    • Développeurs
  • Communauté
    • Créer WordPress
    • Word Camp
    • Rencontres
    • Répertoire de photos
    • Conseil d’emploi
    • Cinq pour l’avenir
  • À propos de
    • À propos de WordPress
    • Vitrine
    • Gutenberg
    • Entreprise
  • Obtenez WordPress

Rechercher plus d’informations

Obtenez WordPress

Ressources pour les développeurs

Parcourir : Accueil/Référence/Fonctions/get_the_post_thumbnail_url()

get_the_post_thumbnail_url( int|WP_Post $post = null, string|int[] $size = ‘post-thumbnail’ ): string|false

Renvoie l’URL de la vignette de la publication.

Contenu

  • Paramètres
  • Revenir
  • La source
  • Crochets
  • Lié
    • Les usages
    • Utilisé par
  • Journal des modifications
  • Notes fournies par les utilisateurs
    • Retour d’information

Parameters $post int|WP_Post Optional

Post ID or WP_Post object. The default is global $post.

Default: null

$string size|int[] Optional

Saved image size to retrieve the source or a flat array of height and width dimensions. ‘post-vignette’ by default.

Default: ‘post-thumbnail’

Top ↑

Come back

string|false Post thumbnail URL or false if no image is available. If $size does not match any registered image size, the original image URL will be returned.

Source

File: wp-includes/post-thumbnail-template.php. See all references

Copy Expand code

function get_the_post_thumbnail_url( $post = null, $size = ‘post-thumbnail’ ) { $post_thumbnail_id = get_post_thumbnail_id( $post ); if (!$post_thumbnail_id) { return false; } $thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size ); /** * Filters the post thumbnail URL. * * @since version 5.9.0 * * @param string|false $thumbnail_url Post thumbnail URL or false if post does not exist. * @param int|WP_Post|null $post Post ID or WP_Post object. The default is global `$post`. * @param string|int[] $size Saved image size to retrieve source or a flat array * of height and width dimensions. ‘post-vignette’ by default. */ return apply_filters( ‘post_thumbnail_url’, $thumbnail_url, $post, $size); } }

View on Trac View on GitHub

Top ↑

Hooks apply_filters( ‘post_thumbnail_url’, string|false $thumbnail_url , int|WP_Post|null $post , string|int[] $size );

Filters the post thumbnail URL.

Top ↑

Related

Top ↑

Uses

Uses

Uses The description
wp_get_attachment_image_url() wp-includes/media.php

Get the URL of an image attachment.

get_post_thumbnail_id() wp-includes/post-thumbnail-template. php

Retrieves the thumbnail ID of the post.

apply_filters() wp-include/plugin.php

Calls callback functions that have been added to a filter hook.

Show 1 more uses Hide more uses

Top ↑

Used by

Used by

Used by The description
the_post_thumbnail_url() wp-includes/post-thumbnail-template. php

Displays the thumbnail URL of the post.

Top ↑

Change log

Version The description
4.4.0 Introduced.

Top ↑

Notes provided by users

  1. Skip to Note 1 content

    You must log in to vote on the helpfulness of this note Vote results for this note: 17 You must log in to vote on the helpfulness of this note

    c4984d705f0aa1821bd69f87100c8d7cContributed by codeunderground — 5 years ago

    Don’t ignore the first parameter. Proper usage of `get_the_post_thumbnail_url()` inside the loop:

    Copy

    if ( have_posts() ) { while ( have_posts() ) { the_post(); /* grab the url for the full size featured image */ $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),’full’); /* link thumbnail to full size image for use with lightbox*/ echo ‘<a href=”‘.esc_url($featured_img_url).'” rel=”lightbox”>’; the_post_thumbnail(‘thumbnail’); echo ‘</a>’; endwhile; endif;

    Log in to add feedback

    Log in to add feedback

  2. Skip to note 2 content

    You must log in to vote on the helpfulness of this note Vote results for this note: 4 You must log in to vote on the helpfulness of this note

    314e068a33b592b8dc0722003878d340Contributed by LindsayMac — 6 years ago

    Downvoted the example posted from @thelilmercoder as it is not proper usage of this function.

    Proper usage of `get_the_post_thumbnail_url()` inside the loop:

    Copy

    if ( have_posts() ) { while ( have_posts() ) { the_post(); /* grab the url for the full size featured image */ $featured_img_url = get_the_post_thumbnail_url(‘full’); /* link thumbnail to full size image for use with lightbox*/ echo ‘<a href=”‘.$featured_img_url.'” rel=”lightbox”>’; the_post_thumbnail(‘thumbnail’); echo ‘</a>’; endwhile; endif;

    Proper usage of `get_the_post_thumbnail_url()` outside the loop:

    Copy

    /* get a specific post object by ID */ $post = get_post(2); /* grab the url for the full size featured image */ $featured_img_url = get_the_post_thumbnail_url($post->ID, ‘full’); /* link thumbnail to full size image for use with lightbox*/ echo ‘<a href=”‘.$featured_img_url.'” rel=”lightbox”>’; the_post_thumbnail(‘thumbnail’); echo ‘</a>’;

    Log in to add feedback

    Log in to add feedback

  3. Skip to note 3 content

    You must log in to vote on the helpfulness of this note Vote results for this note: 4 You must log in to vote on the helpfulness of this note

    07ae9c9407ddc008779b6b405e091c1eContributed by Raul P. — 5 years ago

    It’s worth to note that, if you upload a smaller image (let’s say, a 600px wide) and use this to fetch a specific larger image (let’s say, a 1920px wide for your cover), it will return the original image instead (which is smaller than what you need) instead of returning false.

    If you need to fallback to another image in case the specified file doesn’t exist, you can look into wp_get_attachment_image_src instead, and check for the width or height of the image.

    Log in to add feedback

    Log in to add feedback

  4. Skip to note 4 content

    You must log in to vote on the helpfulness of this note Vote results for this note: -14 You must log in to vote on the helpfulness of this note

    de2d33df4d046ed64bfb37787e6ad742Contributed by Rose — 7 years ago

    To display the featured image with the alt tag use something like this

    Copy

    $thumbnail = get_the_post_thumbnail_url(); if ( $thumbnail ) { $alt_text = get_post_meta( $thumbnail->ID, ‘_wp_attachment_image_alt’, true ); if ( ! empty( $thumbnail ) ) { if ( ! empty( $alt_text ) ) { $alt_text = $alt_text; } else { $alt_text = __( ‘no alt text set’, ‘textdomain’ ); } echo ”; } }

    Log in to add feedback Show Feedback

    Top ↑

    Feedback

    • get_the_post_thumbnail_url() function return a thumbnail URL as string or false on error. So, you can’t access media ID through $thumbnail->ID. This code has error. — By WP Offers — 2 years ago

    • The $thumbnail will return the URL (string), not the image object. This won’t work. You could try to use attachment_url_to_postid( $thumbnail ) to try and get the attachment ID. — By Denis Žoljom — 2 years ago

    Log in to add comments Show comments

You must log in before you can add a rating or comment.

  • About
  • New
  • Accommodation
  • Make a donation
  • Support
  • Developers
  • To be involved
  • Learn
  • Showcase
  • plugins
  • Themes
  • Grounds
  • WordCamp
  • WordPress.TV
  • buddy press
  • bbPress
  • WordPress.com
  • Mast
  • Privacy
  • public code
  • Visit our Facebook page
  • Visit our Twitter account
  • Visit our Instagram account
  • Visit our LinkedIn account

Le code est poésie

Insert/edit link

close

Enter destination URL

URLs

Link text

Open link in new tab

Or a link to existing content

Find more information

No search term specified. Showing recent items. Search or use the up and down arrow keys to select an item.

to cancel

g

Notice

How to get WordPress post thumbnail URL (featured image)?

Ask a question

Asked 10 years ago, 3 months ago

Edited 8 days ago

Seen 511,000 times

This question shows research effort; it is useful and clear

168

This question does not reflect any research effort; it’s not clear or not helpful

New! Save questions or answers and organize your favorite content. Learn more.

View activity on this post.

I use this function to get the featured images:

<a href=”#” rel=”prettyPhoto”> <?php the_post_thumbnail(‘thumbnail’); ?> </a>

Now I want to get the full image by clicking on the anchor tag for which I need a featured image url in

<a href=”here” rel=”prettyPhoto”>

How can I fix this?

  • php
  • wordpress
  • Publish

Share it

Share a link to this question

Copy link CC BY-SA

Improve this question

Follow

Follow this question to receive notifications

modified on October 6 at 7:04

Avatar d'utilisateur de Jesse Nickles

Jesse Nickles

1,065 1 1 gold badge 13 13 silver badges 23 23 bronze badges

requested on June 29, 2012 at 12:3

Avatar d'utilisateur de ManpreetSandhu

ManpreetSandhu ManpreetSandhu

2,045 5 5 gold badges 20 20 silver badges 17 17 bronze badges

Add a comment | 

22 answers

Sorted by: Reset to default

Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)

This answer is helpful

354

This answer is not helpful

Save this response.

View activity on this post.

Check out the code below and let me know if it works for you.

<?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); ?> <div id=”custom-bg” style=”background-image: url(‘<?php echo $image[0]; ?>’)”> </div> <?php endif; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 29, 2014 at 6:56 PM

Avatar utilisateur de Seth

Seth

9,865 10 10 gold badges 44 44 silver badges 68 68 bronze badges

answered on June 29, 2012 at 12:39

Avatar de l'utilisateur de swapnesh

swapness swapness

25.7k 22 22 gold badges 93 93 silver badges 125 125 bronze badges

5

  • 1

    merci beaucoup c’est du boulot je veux ajouter aussi la condition. comme s’ils ont une vignette de publication, montrez-la et si ce n’est pas le cas, une autre image div ou css ou par défaut a une idée de comment

    – pagal

    2 août 2015 à 15h57

  • 2

    i made it but it is correct way or not i don’t know. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); ?> <div class=”section bannerarea cashstudybanner” style=”background-image: url( <?php if ( has_post_thumbnail() ) { echo $image[0]; } else { ?> <?php bloginfo(‘template_directory’); ?>/images/common-banner.jpg <?php } ?> )”>

    –  pagol

    Aug 2, 2015 at 4:35

  • Thank you very much! This code is working perfectly.

    –  Calum Childs

    Jul 21, 2018 at 6:07

  • 2

    Just thought I’d drop by to say I use this answer all the time. It’s downright comical that almost a full decade after this post wordpress still hasn’t simplified this dramatically.

    – Kai Qing

    Tue 11, 2021 at 09:53 PM

  • Thanks a lot. This code works with the user logged in, but the user is not logged in the image is null. Any suggestion for my problem. I am using WP 5.7

    – True

    July 6, 2021 at 2:4 am

Add a comment | 

This answer is helpful

115

This answer is not helpful

Save this response.

View activity on this post.

If you want JUST the source, and not an array with other information:

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->id), ‘thumbnail’ ); ?> <img src=”<?php echo $url ?>” />

 

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on May 20, 2016 at 9:12 PM

Avatar d'utilisateur de Bless

Bless

4,746 2 2 gold badges 41 41 silver badges 43 43 bronze badges

answered on June 29, 2012 at 5:39 PM

Avatar d'utilisateur de LOLapalooza

LOLapalooza LOLapalooza

2,022 3 3 gold badges 17 17 silver badges 22 22 bronze badges

3

  • 3

    For version 4.4.0 and higher wp_get_attachment_image_url().

    –Charlie Oldman

    09/29/2016 at 11:50 a.m.

  • 1

    it was exactly what I needed. load full img src. Thanks!

    – bananaforscale

    November 2, 2016 at 9:31 PM

  • 2

    wp_get_attachment_image_url is only applicable if you know the attachment ID (not the post ID).

    – definitely key

    22/11/2016 at 15:20

Add a comment | 

This answer is helpful

23

This answer is not helpful

Save this response.

View activity on this post.

// Try it inside the loop. <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $feat_image; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified 18 November 2016 at 7:1

answered on July 22, 2013 at 10:51 am

Avatar d'Omprakash Patel

Omprakash Patel Omprakash Patel

528 4 4 silver badges 15 15 bronze badges

1

  • 4

    @gavard.e would actually work with ” instead of ‘ 😛 But the quotes aren’t necessary at all.

    –Ivanka Todorova

    11 Feb 2016 at 11:56

Add a comment | 

This answer is helpful

19

This answer is not helpful

Save this response.

View activity on this post.

Easy way!

<?php wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())) ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on May 7, 2014 at 5:18 PM

Avatar d'utilisateur de Louis Philip Barnett V

Louis-Philippe Barnet V Louis-Philippe Barnet V

407 4 4 silver badges 9 9 bronze badges

0

Add a comment | 

This answer is helpful

19

This answer is not helpful

Save this response.

View activity on this post.

This worked perfectly for me:

<?php echo get_the_post_thumbnail_url($post_id, ‘thumbnail’); ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on March 4, 2016 at 3:2

avatar de l'utilisateur de maxim

maximum maximum

191 1 1 silver badge 2 2 bronze badges

2

  • 4

    Note: Only available since WordPress 4.4.0

    –Marc Guay

    Jul 11, 2016 @ 7:15 PM

  • <?php echo get_the_post_thumbnail_url($post_id); ?> If you want the full size image.

    – yellow

    Sep 20, 2019, 7:14 AM

Add a comment | 

This answer is helpful

ten

This answer is not helpful

Save this response.

View activity on this post.

I think this is the easiest solution and update:

<?php the_post_thumbnail(‘single-post-thumbnail’); ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 11:1

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered Sep 19, 2016 at 3:53 PM

Avatar d'utilisateur de Fredrick Boaz

Frederic Boaz Frederic Boaz

159 2 2 silver badges 7 7 bronze badges

1

  • The one above didn’t work (minus the PHP errors, which I didn’t want as I’m building a WordPress theme for the masses) but this one did. +1

    –Calum Childs

    Sep 26, 2018 at 4:37 PM

Add a comment | 

This answer is helpful

8

This answer is not helpful

Save this response.

View activity on this post.

This is the simplest answer:

<?php $img = get_the_post_thumbnail_url($postID, ‘post-thumbnail’); ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 11:1

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on March 4, 2017 at 5:1

Avatar d'utilisateur de Vishwajeet Mishra

Vishwajeet Mishra Vishwajeet Mishra

79 1 1 silver badge 1 1 bronze badge

Add a comment | 

This answer is helpful

8

This answer is not helpful

Save this response.

View activity on this post.

You can try this:

<?php $feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); echo $feat_image; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 14:5

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on March 31, 2015 at 1:53 PM

avatar d'utilisateur de nim

nim-nim

479 6 6 silver badges 15 15 bronze badges

2

  • this displays only: ‘$feat_image’;

    –Stephen Johanson

    May 11, 2015 at 12:43 p.m.

  • my error is, echo $feat_image;

    – to know

    June 16, 2015 at 7:16 a.m.

Add a comment | 

This answer is helpful

6

This answer is not helpful

Save this response.

View activity on this post.

try this one

<?php echo get_the_post_thumbnail($post_id, ‘thumbnail’, array(‘class’ => ‘alignleft’)); ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 14:5

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on February 5, 2014 at 1:53 PM

Avatar d'utilisateur de Yahya Akhtar

Yahya Akhtar Yahya Akhtar Free Mp3 Download

241 3 3 silver badges 16 16 bronze badges

1

  • 1

    Use get_the_post_thumbnail_url if you only want the image URL.

    – Gavin

    Sep 23, 2019, 8:35 a.m.

Add a comment | 

This answer is helpful

5

This answer is not helpful

Save this response.

View activity on this post.

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

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

Which just gives you the full image URL without the entire <img> tag.

Hope this can help you.

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on February 6, 2020 at 7:5 PM

Avatar de l'utilisateur de Jodyshop

JodyshopJodyshop

638 8 8 silver badges 11 11 bronze badges

Add a comment | 

This answer is helpful

3

This answer is not helpful

Save this response.

View activity on this post.

You can try this.

<?php $image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?> <a href=”<?php echo $image_url;?>” rel=”prettyPhoto”>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on January 20, 2016 at 4:13 PM

Avatar de Jakir Hossain

Jakir Hossain Jakir Hossain Free Mp3 Download

2,427 17 17 silver badges 23 23 bronze badges

Add a comment | 

This answer is helpful

3

This answer is not helpful

Save this response.

View activity on this post.

You can also get it from post_meta like this:

echo get_post_meta($post->ID, ‘featured_image’, true);

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on March 24, 2017 at 2:00 PM

Avatar d'utilisateur de Dhyey

Dhyey Dhyey

4 168 3 3 gold badges 25 25 silver badges 33 33 bronze badges

Add a comment | 

This answer is helpful

3

This answer is not helpful

Save this response.

View activity on this post.

You can also download the URL of attached images as follows. It works well.

if (has_post_thumbnail()) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘medium’); } }

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 11:0

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on May 13, 2014 at 3:10 p.m.

avatar d'utilisateur de farhan

farhan farhan

31 1 1 bronze badge

Add a comment | 

This answer is helpful

3

This answer is not helpful

Save this response.

View activity on this post.

You will try this

<?php $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID), ‘full’); ?> // Here you can manage your image size as medium, thumbnail or custom size <img src=”<?php echo $url ?>” />

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 11:1

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on December 6, 2017 at 06:34

Avatar d'utilisateur de Viral M

Viral M Viral M

271 2 2 silver badges 14 14 bronze badges

Add a comment | 

This answer is helpful

1

This answer is not helpful

Save this response.

View activity on this post.

<?php if (has_post_thumbnail( $post->ID ) ): $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); ?> <img src=”<?php echo $image[0];?>”><?php endif; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified 21 March 2017 at 6:5

answered on March 21, 2017 at 6:4

Avatar d'utilisateur de Dhruvin Moradiya

Dhruvin Moradiya Download, Listen and View for Free Dhruvin Moradiya MP3, Video and Lyrics

548 2 2 gold badges 10 10 silver badges 20 20 bronze badges

Add a comment | 

This answer is helpful

1

This answer is not helpful

Save this response.

View activity on this post.

If the post is an image and we already know what it is, it’s possible to get the thumbnail URL without too much hassle:

echo pathinfo($image->guid, PATHINFO_DIRNAME);

Share it

Share a link to this answer

Copy link CC BY-SA 4.0

Improve this answer

Follow

Follow this answer to receive notifications

edited Jul 2, 2019 at 14:48

Avatar d'utilisateur de Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered Oct 29, 2018 at 23:59

User avatar of Harry Bosh

Harry Bosh Harry Bosh

3,264 1 1 gold badge 32 32 silver badges 33 33 bronze badges

Add a comment  | 

This answer is useful

1

This answer is not useful

Save this answer.

Show activity on this post.

Simply inside the loop write <?php the_post_thumbnail_url(); ?> as shown below:-

$args=array(‘post_type’ => ‘your_custom_post_type_slug’,’order’ => ‘DESC’,’posts_per_page’=> -1); $the_qyery = new WP_Query($args); if ($the_qyery->have_posts()): while ( $the_qyery->have_posts() ): $the_qyery->the_post();?> <div class=”col col_4_of_12″> <div class=”article_standard_view”> < <a href=”<?php the_permalink(); ?>”><img src=”<?php the_post_thumbnail_url(); ?>” alt=”Post “></a> </div> </article> < /div> </div> <?php endwhile; end if; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

answered on February 24, 2020 at 10:00 am

Joy user avatar

joy joy

39 4 4 bronze badges

Add a comment | 

This answer is helpful

0

This answer is not helpful

Save this response.

View activity on this post.

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 modify the thumbnail_size value according to the required size.

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 2:49 PM

User avatar of Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on January 4, 2018 at 12:18

Avatar of Mohammad Farhan Atif Wattoo

Mohammad Farhan Atif Wattoo Download, Listen and Watch Free Mohammad Farhan Atif Wattoo MP3, Video and Lyrics

51 3 3 bronze badges

0

Add a comment | 

This answer is helpful

0

This answer is not helpful

Save this response.

View activity on this post.

You can also download the URL of attached images as follows:

<?php “<div><a href=”.get_permalink(id).”>”.wp_get_attachment_url(304, array(50.50), 1).”</a></div>”; ?>

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on July 2, 2019 at 14:5

User avatar of Peter Mortensen

Peter Mortensen

30.6k 21 21 gold badges 102 102 silver badges 124 124 bronze badges

answered on May 8, 2014 at 9:35 am

User avatar of user3615759

user3615759 user3

9 2 2 bronze badges

Add a comment | 

This answer is helpful

0

This answer is not helpful

Save this response.

View activity on this post.

You can get the src image for a specific size using the wp_get_attachment_url function.

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->id), ‘full’ ); ?> <img src=”<?php echo $url ?>” />

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Follow

Follow this answer to receive notifications

modified on November 30, 2021 at 14:3

answered on November 16, 2021 at 11:4

User avatar of Vicky P

Vicky P Vicky P

463 6 6 silver badges 11 11 bronze badges

Add a comment | 

This answer is helpful

0

This answer is not helpful

Save this response.

View activity on this post.

if you want to get the full image size from the post thumbnail you can use this code.

$img_url = wp_get_attachment_image_url(get_post_thumbnail_id(get_the_ID()), ‘full’); <img src=”<?PHP echo $img_url?>”>

here get_the_ID() is the post ID.

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Continue

Follow this answer to receive notifications

replied on February 23 at 8:44

Avatar of Arman H

Arman H Arman H. Free Mp3 Download

1,435 16 16 silver badges 22 22 bronze badges

Add a comment | 

This answer is helpful

-1

This answer is not helpful

Save this response.

View activity on this post.

<img src=”<?php echo get_post_meta($post->ID, “mabp_thumbnail_url”, true); ?>” alt=”<?php the_title(); ?>” width=”100%” height=” / >

Share it

Share a link to this answer

Copy link CC BY-SA

Improve this answer

Continue

Follow this answer to receive notifications

answered on March 5, 2017 at 1:17 PM

Mizo Games User Avatar

Mizo Games Mizo Games

159 1 1 silver badge 8 8 bronze badges

1

  • Can you elaborate?

    –Peter Mortensen

    Jul 2, 2019 at 2:50 PM

Add a comment | 

Very Active Question Earn 10 reputation points (not including association bonus) to answer this question. The reputation requirement helps protect this question from spam and no-response activity.

Not the answer you are looking for? Browse other tagged questions

  • php
  • wordpress
  • Publish

or ask your own question.

  • The overflow blog
  • How Observational Development Creates Elite Artists

  • The robots are coming… but when? (Ep 496)

  • Featured in Meta
  • Markers have become registered

  • Inbox improvements: mark notifications as read/unread and filter…

  • Collectives update: recognized members, articles and GitLab

  • The [script] tag burns

Linked to

2

How to get post thumbnail url

1

WordPress Template: Highlight Image Slider Control Does Not Display Image

1

how to display featured image in wordpress using $wpdb class

0

Display latest wordpress image highlights on static html page

0

Set featured image as post background image

0

Different header image for each wordpress post

Related

1239

Secure hash and salt for PHP passwords

6092

What is the difference between POST and PUT in HTTP?

435

Saving image from PHP URL

1927

How to display PHP errors?

2719

How to get YouTube video thumbnail from YouTube API?

4966

Reference — What does this symbol mean in PHP?

975

Get Full URL in PHP

1254

Reference – What does this error mean in PHP?

1683

How are parameters sent in an HTTP POST request?

Net burning questions

  • How do I counter special ops attacks that use the gaseous form?
  • How to get from Detroit to Windsor without a tunnel, bus or car
  • Why didn’t soldiers eat beef killed by their enemies?
  • Countries with a very plural congress/parliament
  • Short sci-fi story about AI creatures that eventually escape to another dimension
  • Book where the narrator is a dog
  • Is the source of the term “smoke test” from testing electronic equipment?
  • Change link color based on background color?
  • You can’t shift to the lowest gear on a new road bike (photos)
  • What does ‘Gulpin Gargoyle’ mean?
  • Why is Color Index measurement used?
  • How can there be wars/battles/fights in a universe where no one can die?
  • ST_Difference(A, B) returning A when A is entirely contained in B
  • Are pre-pasted patch kits recommended?
  • Do I need my supervisors to double check the item at the style correction stage?
  • Is there an evolutionary advantage for 10% of my Homo mammalian species to have Von Willebrand blood clotting disease?
  • Does DSolve give a general solution?
  • What is the name of the game of this image?
  • Why doesn’t my ORDER BY in STRING_AGG always work?
  • Good references for lower cost arrangements?
  • Is it possible to fly around the world to linger in broad daylight with a fighter plane?
  • How to create an array of conjugate values ​​from two arrays?
  • Understanding the Suspicious HTTP GET Request
  • Export dots as dots, text as text (when exporting to svg)

Question flow

Subscribe to RSS

Question flow

To subscribe to this RSS source, copy and paste this URL into your RSS reader.

g

Google Google Translator


Video Get featured image url wordpress

Related Posts

Free chat room code for my website

Contents1 How to set up a free chat room on the website.2 3 comentarios2.1 Trackbacks/Pingbacks2.2 Submit a Comment Cancel reply3 How to Create a Chat Room Website…

Background image full screen css

Contents1 Cómo – Full Page Image1.1 Example1.2 Example2 CSS background image tamaño tutorial: how to codify a complete page background image3 Perfect Full Page Background Image3.1 Méthode CSS géniale,…

WordPress leverage browser caching

Contents1 Aproveche el almacenamiento in hidden del navegador1.1 Will it works for my website?1.2 Where are plugin options1.3 Some JavaScript files still display under Leverage Browser Caching1.4…

WordPress post to facebook page

Contents1 How to Automatically Post to Facebook from WordPress1.1 Download Now: How to Launch a WordPress Website [Free Guide + Checklist]1.2 1. Create an IFTTT account.1.3 2….

Download images from wordpress media library

Contents1 How to export your WordPress media library1.1 Download maintenant : How to launch a WordPress website [Free Guide + Checklist]1.2 How to export your WordPress media…

WordPress single post template

Contents1 How to Create Custom Unique Post Templates in WordPress2 Post Template Files2.1 author.php2.2 Fecha.php3 Handbook navigation4 How to Create Custom Single Post Templates in WordPress5 Video…