Easy Code for Featured Images in WordPress®
Below is a really easy code sample for utilizing featured images in WordPress®.

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.
FOR COPYING & PASTING PURPOSES:
<?php
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’;
}
?>
What you should do next . . .
Your website is the most important marketing tool you have for your business. Investing in quality code and marketing is the key to industry leadership.
Join our newsletter, where you will learn educational info on latest insights, tips and best practices.
Share:
About Us
Did you know more than 200 clients have worked with PaperStreet for more than 10 years?
Get a Free Website
Analysis and Consultation
Marketing Services