Set featured image as div background
-
From searching on this forum and others I have found this code (which works)
<?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="category-name" style="background-image: url('<?php echo $image[0]; ?>')"> </div><!-- end #category-name --> <?php endif; ?>
What I need now is the Else statement – to set the background to a default image if there isn’t a specified “featured image”.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Set featured image as div background’ is closed to new replies.