Easy Code for Featured Images in WordPress

A white, rounded square logo with an abstract S-shaped design on a gradient blue and purple background.

Below is a really easy code sample for utilizing featured images in WordPress.

Easy Code for Featured Images in WordPress: A PHP code snippet for determining and extracting the URL of a post's featured image or setting a default image if none exists.

To implement this you would basically just copy and paste the code snippet (found in text format below) where you want to utilize the featured image section in WordPress and the $featured_image variable would return the URL of the featured image.  The ‘else’ part of the statement sets a fallback (default) photo if a featured image is not chosen for a specific page.

Simple, but nice.




if(has_post_thumbnail()) { // check if the post has a Featured Image.

$photo = get_the_post_thumbnail();

$featured_image = explode(‘”‘, $photo);

$featured_image = $featured_image[‘1’];

} else {

$featured_image = ‘/wp-content/themes/paperstreet/images/default.jpg’;



Share This

Join the Sales and Marketing News, receive our last insights, tips and best practices.

Our 7 Guarantees

Keeping 2,000+ Clients Happy Since 2001.

You Will Love Your Design We design to please you and your clients
Same-Day Support 24-hour turnaround edits during business hours
Free Education We provide knowledge to help you expand
No Hidden Charges We quote flat-rate projects
Own Your Site No strings attached
We Create Results SEO, PPC, content + design = clients
We Make Life Easier One agency for web, branding and marketing