How Do I Find the URL of a Featured Image in WordPress?

Looking for the URL of a featured image in WordPress? There are a few different ways to find the URL of a featured image in WordPress.

Method 1: Use the Media Library

To find the URL of a featured image in the WordPress media library, use the get_media() function. This function takes a path as an argument and returns the full URL of the image file located at that location.

For example, the following code snippet would return the URL of the featured image located at the path /wp-content/uploads/2015/03/winter-wonderland.jpg:

get_media(‘/wp-content/uploads/2015/03/winter-wonderland.jpg’);

Method 2: Use the Media Query Syntax

Another way to find the URL of a featured image in WordPress is to use the media query syntax. The media query syntax allows you to query specific media elements based on certain conditions.

For example, you could use a media query to query for the URL of a featured image only if the page is viewable in a desktop browser. To use the media query syntax, add the query condition to the header of your WordPress theme or plugin file.

For example, the following code snippet would return the URL of the featured image only if the page is viewable in a desktop browser:

@media only screen and (max-width: 640px) {

}

Conclusion

Both methods of finding the URL of a featured image in WordPress are useful. The get_media() function is useful if you want to access the URL of the image file located in the WordPress media library.

The media query syntax is useful if you want to query for the URL of a featured image based on certain conditions, such as viewability in a desktop browser.