Featured Image as CSS Background
-
Hello,
I am having some trouble with this woundering if maybe someone can help!
So I have set a featured image to my Blog page and in the template files I have the following:
<?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); $image = $image[0]; ?> <?php else : $image = get_bloginfo( 'stylesheet_directory') . '/img/default-featured-img.jpg'; ?> <?php endif; ?> <div class="feature" style="background-image: url('<?php echo $image; ?>')">
It shows the default-featured-img.jpg but it can not seem to find the attached featured image that I set! so it is using the else section of the PHP.
Thanks
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Featured Image as CSS Background’ is closed to new replies.