Wordpress - Get featured image url


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.