Close Menu
wpexpelorwpexpelor
  • WordPress Beginner tips
  • WordPress Security
  • about us
  • contact us
Facebook X (Twitter) Instagram Pinterest
Facebook X (Twitter) Instagram Pinterest
wpexpelorwpexpelor
  • WordPress Beginner tips
  • WordPress Security
  • about us
  • contact us
wpexpelorwpexpelor
Home»WordPress Beginner tips»WordPress php get featured image url
WordPress Beginner tips

WordPress php get featured image url

NinaBy NinaNovember 22, 2023Updated:December 3, 2023No Comments3 Mins Read
WordPress php get featured image url
WordPress php get featured image url
Share
Facebook Twitter LinkedIn Pinterest Email
5/5 - (1 vote)

This article is about my experience with the “wordpress php get featured image url”.once, I wanted to get a featured image URL, and my website theme didn’t support this option. If you have experienced the same problem or you just want to access the featured image URL in wordpress, stay with me! You can add this option to the wordpress theme with a simple little code.

Contents show
1 wordpress php get featured image in 5 minutes!
2 wordpress php get featured image url

wordpress php get featured image in 5 minutes!

To get featured image url, follow the instructions: 

  1. Open your wordpress theme folder and find the “functions.php” file.
  2. Add this code to “functions.php”.
if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
}

This code lets you use the featured image on your website.

wordpress php get featured image url
wordpress php get featured image url

If you want to show a wordpress featured image on the website homepage, simply use this code:

<?php
the_post_thumbnail();
?>

Note: when you don’t mention size in Parentheses default size “thumbnail” will be set automatically.

If you wish to set the size as you desire, here is the five standard size that you can use:

the_post_thumbnail( 'thumbnail' );
the_post_thumbnail( 'medium' ); 
the_post_thumbnail( 'medium_large' );
the_post_thumbnail( 'large' );
the_post_thumbnail( 'full' );

Note: use this code only in the content display loop. As a sample:

<?php while ( have_posts() ) : the_post();?>
<?php the_post_thumbnail(); ?>
<?php endwhile;?> 

wordpress php get featured image url

I already explained how to define featured image for the wordpress theme, but what if you want to get image URL to use in different parts of the website? Imagine you want to use a featured image as a background for a section. Attention! This part of the code is not handy at all!

<img src="<?php the_post_thumbnail(); ?>">

But why is it wrong to use this code? As you see, you have put an image on the “img tag,” not its address! In fact, we need to put the image address URL in the “image tag,” not the image itself!
So we want to solve the problem: wordpress php get featured image url. Simply use this code:

<?php 
$featured_img_url = get_the_post_thumbnail_url(get_the_ID()); 
?>

Instead of “featured_img_url,” you can use any name to set a variable. By using that code, I mentioned you could save the wordpress featured image address in the “featured_img_url” variable.

wordpress php get featured image url
wordpress php get featured image url

Now, just use it anywhere you want.
Here is the right code:

<img src="<?php echo $featured_img_url; ?>">

As you see, I’ve put the amount in the varible “featured_img_url” in “image tag”!
What is it? YES! wordpress featured image url!
The job is done! As you see, we can easily get the wordpress php featured image url by using some simple code. I hope this tutorial in wpexpelor is useful for you, and as usual, ask me any questions in the comments. It would be great to hear from you! Good Luke!

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit VKontakte Telegram WhatsApp
Previous ArticleHow to change theme name WordPress
Next Article  WordPress failed to import media solutions!

Related Posts

woocommerce user registration form without email

June 9, 2024

Edit Author Slug in WordPress

January 30, 2024

install 2 wordpress on same domain

January 23, 2024

Leave A Reply Cancel Reply

Trending
WordPress Database

WordPress Show Data From Database

By NinaDecember 12, 20230

WordPress show data from database is a keyword most of you search on the web…

affordable local seo services in houston

June 28, 2025

SEO Services in texas

May 30, 2025

woocommerce user registration form without email

June 9, 2024

Edit Author Slug in WordPress

January 30, 2024
Social
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
Facebook X (Twitter) Instagram Pinterest
©2025 WPexpelor. All Rights Reserved.

Type above and press Enter to search. Press Esc to cancel.