Monday, April 14, 2014
how to set featured image as background wordpress
Syntax
Use the following to get image
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<?php endif; ?>
CSS Code
Use this CSS code to add background image.
<style type="text/css">style=background-image: url('<?php echo $image[0]; ?>')</style>
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment