Use Featured Image as Background Image in WordPress

featured image

To use your WordPress featured image as a background image, simply use the code below. Place the first line after your header call and add the style to the div you want. make sure to style your div properly to your liking.

Additionally, we can use what we created above but tweak it a bit. Here we will add a fallback background image in the mix just incase something goes wrong with a media file or someone forgets to add a featured image. As you can see we are linking to an image located in a “images” folder in your theme.

Happy coding!