divider

Easy Code for Featured Images in WordPress

Services: Law Firm Website Design . SEO . Internet Marketing . Law Firm Marketing Guide . Content Marketing . PPC

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

Code1

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’;

}

?>


Related Posts