I found the solution from a WordPress forum and this is what they used. Works perfect
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' );
$image = $image[0]; ?>
<?php else :
$image = get_bloginfo('stylesheet_directory') . '/lib/images/home1-1024x681.jpg'; ?>
<?php endif; ?>
<section id="halfpro" style="background-image: url('<?php echo $image; ?>')" >
Related Posts:
- How do I change/modify the_post_thumbnail(); html output?
- Else/If Statement to Display Photo Descriptions
- not outputting medium size image URL
- add if statement to the featured image
- Remove default Image Sizes
- Generate and upload screenshot as featured image for user-submitted post
- What’s the best way to use the Featured Image for responsive web design?
- How to add a class to the attachment images
- How to draw media details for Isotope gallery using Photoswipe
- How to register images uploaded via FTP in media library?
- Adding Featured Image to Post programatically
- Add custom image sizes to media uploader
- How to upload imagick resource to media in wordpress
- How do I get images (with a thumbnail preview) to show in search results?
- Using wp_get_image_editor in a standalone script
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Assign a picture URL to a page via PHP
- Change logo based on incoming domain
- How to scale image with equal width and height without distortion?
- How to Display Image Meta underneath EVERY image in EVERY post
- Convert all images to PNG on file upload
- Echo URL of large version of Featured Image
- How to get specific image in media library with php
- Recent posts with featured image or fallback image with permalink
- How to control WordPress image metadata (using Imagick)?
- Scrape external webpage for first image and add it to new post
- Redirect to another page using contact form 7? [closed]
- height should be set to auto to avoid pixelation in the post thumbnail function
- Three Questions with Twenty Eleven theme
- Resize image to specific dimension (X to Y ratio)
- Get featured image with custom size outside WordPress
- How to set a featured image (thumbnail) with PHP?
- Image rotation issue (horizontal picture uploading as vertical) — Exif issue?
- Fallback image URL if no featured image exists via a shortcode function
- Generate responsive post thumbnails of same size
- How to Make Thumbnail of Post Stay Animated
- Get the alt text of the image in a array
- Adding a ‘style=’ bit to image_send_to_editor output
- Convert all uploaded PNG files to PNG-8 format
- Retrieve alt text by referencing the img src
- Add Featured Image to Existing Post
- How to use data URL in WordPress?
- Replace background image with post thumbnail in shortcode
- Resize post thumbnail
- How to put 2 php codes in functions.php without site crashing
- How to link all featured images to custom url in single.php for only non-logged-in users?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Retrieving specific images from Media Library
- How do I routinely extract the thumbnail of the most recent post?
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- add class to background image
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- Overwriting a Shortcode
- Setting post thumbnail sizes in template file and functions.php
- Understanding responsive imagery
- WooCommerce: write featured image dimensions to custom fields in product’
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- Image alt tag is showing post title instead of Alt Text
- Missing feature image link function
- How to set and use global variables? Or why not to use them at all
- How to deprecate a function used in a plugin?
- How to manually fix the WordPress gallery code using PHP in functions.php?
- How to make a image-size selected by default in Media upload – WP v3.5
- What is This esc_html_e() i wordpress php?
- Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
- How to Add Image to WordPress RSS-Feed with no Plug-in?
- Function to return true if current page has child pages
- Mega Menu Walker
- start_lvl Ignored in Custom walker_nav_menu
- Enforcing password complexity
- PHP code in page template vs functions
- Apply class to every paragraph that holds image?
- Remove “Insert from URL” link in Media upload – WP 3.5
- static variable loop not working in WordPress
- Cleaning up WordPress to improve performance?
- Displaying Logged-In User Name in WordPress Menu
- Hide main div if wp_nav_menu is empty
- Proper use of Output Buffer
- List of all theme customizer control types?
- Autoloading in Child Theme
- Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]
- Modify previous and next text from pagination links
- Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
- How do I hook into WordPress to save an uploaded photo as an alternate size to an existing photo?
- Need help setting default setting value for radio button in theme customizer
- How to check if image is already stored in a site’s post database? (network)
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Should I write a PHP function in home.php?
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- Edit tag cloud widget number
- Adding a custom image upload size and making it selected by default?
- adding a filter to a shortcode?
- username_exists() function can’t be access without logging in
- Hide custom image sizes from media library
- Customize default settings on new sites on multisite