How to Get Featured Image URL in WordPress? - TIPsoont

How to Get Featured Image URL in WordPress?

How to Get Featured Image URL in WordPress

Whether you are building a theme or plugin from scratch or want to modify the existing one – as a web developer or designer, a featured image URL in WordPress will save you time for future use and serve many purposes. 

However, it is not a built-in feature in WordPress. 

Luckily, the process is straightforward. All you need is a bit of customization in your theme’s function.php file.

So, let’s find them out together.

Why Get Featured Image URL in WordPress?

However, the media library is the ultimate resource where WordPress images are stored. This allows easy access to images and their URLs after uploading.

Still, there can be specific reasons why you should also get the featured image URL in WordPress. 

A few of them are;

  • Firstly, if you are a blogger, you may have several websites and wish to use an image uploaded from one website to another. The featured image URL is just a lifesaver that has made the daunting process a lot easier.
  • Another significant advantage is your web server, which will take a particular space once you upload an image in WordPress. After your website grows, you may have to buy additional space. However, having WordPress images stored in the mother site instead of the server will save you cost.

In a nutshell, to make your time productive and save time – image URLs are helpful, especially if you manage multiple sites. 

How to Get the Post Thumbnail or Featured Image URL in WordPress?

To grab user attention, WordPress-featured images always play a crucial part. Whether you need to share on any social media platform or a user pops up to your first. The first ever impression will be your featured image. 

So, getting a featured image URL is essential.

For this, you only need to paste a code that we will discuss in today’s step-by-step guide. 

Step 1: Create a backup

Initiate the process by creating a backup or child theme for your website. 

This will help you to restore your data if something unexpected happens, and you can quickly restore or export WordPress posts. 

Step 2: Enable feature image support

After creating a backup, you need to enable the feature image support.

However, if you are building a theme from scratch, you may have yet to enable this feature, and adding theme support for thumbnails is required. 

Otherwise, most of the WordPress themes would have this function enabled. To check, you must know if you’re not getting an option to upload a featured image while editing a post. It means the feature image option is disabled, and adding a code will resolve the issue. 

Remember, you can easily change the WordPress thumbnail after uploading and publishing. 

Step 3: Use this code

To enable this function, you only need to insert the code mentioned below in the function.php file, which will potentially resolve the issue.

<?php//Enable theme support for featured imagesadd_theme_support(‘post-thumbnails’);?>

Good to know: You can easily access the function.php file from the appearance > theme editor section of your WordPress dashboard. Available at the top-right side.

Get Featured Image URL with PHP code:

Another most accessible way to get a featured image URL is using the code below. 

echo get_the_post_thumbail_url (get_the_ID (), ‘medium’ ;

The biggest perk of using this method is that you can change the size of the WordPress-featured image by customizing the code.

For example, as you can see, “medium” is mentioned in the code, representing the size. And to make changes, you can simply use “full,” “large,” or “original,” or add your desired size there. 

What to Do If Your WordPress Featured Image URL is Not Returning?

The most apparent reason you are facing trouble is that your featured image support is not enabled, or your desired theme doesn’t support this feature.

In case you just enable this feature first (process stated above).

This could resolve the issue. 

Bottom Line:

Wrapping up the discussion with a note that Images are the primary source to visualize your written text. That’s why you should also focus on the quality of them.

For example, WordPress images should be clear and accurately represent what is about to be discussed.

Hopefully, this guide has created some value in yours, however, if you still need clarification and have any more queries. 

Do write in the comment section, and don’t forget to subscribe to our newsletter for more exquisite posts like this. 

Till Next!

Admin
Social Media

YOU MAY ALSO LIKE

Leave a Reply

Your email address will not be published. Required fields are marked *