/ Published in: PHP

This code will retrieve the url of a featured image in order to use it as a background.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php if (has_post_thumbnail( $post->ID )) : ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <div id="custom-bg" style="background-image: url('<?php echo $image; ?>')"> </div> <?php endif; ?>
Comments
