Set featured image as background?

Viewing 2 posts - 1 through 2 (of 2 total)
  • #20702
    cyril
    Participant

    Is there a way to set the featured image of a page as the background? I’ve been searching and found couple of lines of code on google.

    https://wordpress.org/support/topic/using-this-code

    Any idea on how to approach this?

    #20886
    Daniel Tara
    Keymaster

    This function should do the job:

    add_filter( 'theme_mod_background_image', 'enlightenment_featured_image_background' );
    
    function enlightenment_featured_image_background( $image ) {
    	if( is_singular() && has_post_thumbnail() ) {
    		return wp_get_attachment_url( get_post_thumbnail_id() );
    	}
    	
    	return $image;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.