How To Get Featured Image Url In WordPress

Featured images are an essential aspect of any WordPress blog, showcasing the main visual element of your content. They create an instant impression and attract the attention of the reader. Sometimes, you may want to use the featured image URL directly in your code or display it for some other purpose. In this blog post, we will cover different methods to get the featured image URL in WordPress.

Method 1: Using the wp_get_attachment_url() Function

The most common and simple method to get the featured image URL is by using the wp_get_attachment_url() function. This function returns the URL of the attachment (image) based on the attachment ID. Here’s how you can use it:

  1. First, get the featured image ID using the get_post_thumbnail_id() function.
  2. Then, pass this ID as an argument to the wp_get_attachment_url() function.

Add the following code snippet to your WordPress theme’s template file where you want to display the featured image URL:


Method 2: Using the get_the_post_thumbnail_url() Function

Another simple method to get the featured image URL is by using the get_the_post_thumbnail_url() function. This function directly returns the URL of the post thumbnail (featured image). Here’s how you can use it:

Add the following code snippet to your WordPress theme’s template file where you want to display the featured image URL:


Method 3: Using the wp_get_attachment_image_src() Function

If you want to get more information about the featured image, such as the width and height, you can use the wp_get_attachment_image_src() function. This function returns an array containing the URL, width, and height of the attachment (image). Here’s how you can use it:

  1. First, get the featured image ID using the get_post_thumbnail_id() function.
  2. Then, pass this ID as an argument to the wp_get_attachment_image_src() function.

Add the following code snippet to your WordPress theme’s template file where you want to display the featured image URL:


These are the three common methods to get the featured image URL in WordPress. You can choose any of these methods based on your specific requirements and preferences. Happy coding!