Adapted from this thread on the WP forums:
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail'); ?>
<style>
#banner-id {
background-image: url('<?php echo $image[0]; ?>');
}
</style>
<?php endif; ?>
Add this to your single page template, after the_post()
. I’d reccommend having a default header image so that if the page doesn’t have a featured image it falls back to using that.
'single-post-thumbnail'
can instead be an array with the ideal header dimentions, such as array(600, 30)
.
Related Posts:
- How to change image type for specific size?
- How to insert images into posts without using Add Media dialog
- How can I determine if a post has an image attachment?
- Img Src File path issue
- replace wp_get_attachment_image with my own function
- Images dont show in grid view, but do in list view
- Automating a Daily Picture Blog?
- Default image for homepage when shared in social media
- Disable WordPress Big Image Size Scaling
- How to display a shortcode caption somewhere other than the_content
- Frontend image uploading from edit profile page. (goldenapples)
- Allowing post attachments without allowing to insert in text
- Hook for saving an image after editing
- How to store media files in subdomain
- get attributes/part of the gallery shortcode
- extract post image to be featured images
- Sidebar slideshow widget [closed]
- Image file sizes increasing on upload
- How to Change WordPress Image URLs
- How do I remove generated HTML around images in posts?
- Different upload path per file type
- Animated Gif image not uploading correctly
- HTML tags in WordPress image caption
- How can I upload an image for background use using the Theme Editor in WordPress?
- Can an image have more than one parent_post?
- Where are the resized images coming from?
- unattached media files that should be attached
- Keep image EXIF info after compressing original image?
- Set Post Image Using Shortcode
- Print specific image size in galley loop
- How can I attach hotlinked images in posts/pages within the same server?
- WordPress Image Attachment using remote image
- Migration to WP – Couldn’t load image
- How can I create more upload paths, like a post corresponding to a post title folder used to store images of the same product
- Every admin only can see his uploaded images im editor
- Multiple amp-image overlays. How to properly do this in wordpress?
- Update an image block style programatically
- Resize into square the single product image in woocommerce without cropping [closed]
- an error occurred in the upload. please try again later (Maybe File Permission Issue)
- Image Upload HTTP 500 Internal server error
- Animated GIF on WordPress posts? [closed]
- Generate images to be associated for tag and category?
- convert post title to image
- Can you check if a post WYSIWYG field has an image in it?
- how to put image and text on same line [closed]
- Different background images on different sites [closed]
- How to know what size image to use for background? [closed]
- Understanding WordPress image sizes and responsive images
- Image large size [closed]
- Google Page Speed Insights – Optimize Images
- Is there a way in WordPress to convert images to WebP without a plugin?
- Partial img lazy load with WP 5.5
- Why doesn’t WordPress use the smaller sized image?
- css to fit image by HEIGHT
- Can’t see images in posts after migrating site to subdomain
- Alt Image WordPress [closed]
- Some Images Disappeared from Media Library?
- What is required in the hosting environment for WordPress to process an image into multiple sizes?
- Get an image from url, resize it, and save on a custom folder (not the media library)
- Images dont show up on an iPhone [closed]
- Moving an image to the side [closed]
- Placing a featured image into header
- Function to grab specific image IDs from media library.
- How to add thumbnails to posts and pages automatically in a uniformed fixed elegant way?
- image upload/edit is broken: “Image data does not exist. Please re-upload the image.”
- Background Image Does Not Display on Page
- Can’t fix corrupted images
- How can we upload common images only to AWS S3 using WordPress?
- Deleted Image giving a 301
- Avatar picture is broken
- WordPress append -1 to the image name
- wpdb function for filtering the images by title
- Link to products with the same image title (woocommerce)
- How to echo images Urls from a wordpress post, that are relally in the post
- Adding Post Thumbnail to Metro Pro Theme
- media_handle_upload() with 1 image under 1Mb chokes my server and returns timeout error
- WordPress does not load most theme images
- convert images and media url into blob url
- How to add featured image use HTML
- Correct color profile and saving? Thumbnail creation?
- New portfolio items appearing smaller on the grid
- Modify media file markup output
- Theme page headers and rotator images not assigned after website migration
- WPML – Change media uploader language
- Image thumbnail on single product issue | WooCommerce
- WordPress Is Saving Original Image Only
- How can I hook and edit on the fly an image uploaded
- Anomaly with response coming from XML RPC Api get Post (integer out of range)
- Create a custom attachment thumbnail for quick page load
- Change the image for a certain URL
- How to make an image bigger with wp_get_image_editor
- Multiple gallery thumnbnails on one page
- Change image link in excerpt to point to post
- Putting the title attribute in image tag — Snapshot Theme from Woothemes
- Post migration – images do not display
- wp_handle_upload Image sizes
- Display Images from Array with wp_get_attachment_image() [closed]
- WP_Image_Editor – How to save the new size of the image in the sizes metadata
- Is is possible to append .webp to srcset images using wp_filter_content_tags()?
- Could a very long article slow down all website and wpadmin?