Posted By

jli on 11/12/10


Tagged

url image wordpress featured


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vehler
hkamci


Wordpress - Get featured image url


 / Published in: PHP
 

This code will retrieve the url of a featured image in order to use it as a background.

  1. <?php if (has_post_thumbnail( $post->ID )) : ?>
  2. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
  3. <div id="custom-bg" style="background-image: url('<?php echo $image; ?>')">
  4.  
  5. </div>
  6. <?php endif; ?>

Report this snippet  

You need to login to post a comment.