Skip to content

Snippet: Display Blog Post Featured Image As Page Header Background

// Changes your blog page header style to background image if a featured image exists
add_filter( 'totaltheme/page/header/style', function( $style ) {
	if ( is_singular( 'post' ) && ! $style && has_post_thumbnail() ) {
		$style = 'background-image';
	}
	return $style;
} );

// Adds your featured image to the page header
add_filter( 'wpex_page_header_background_image', function( $image ) {
	if ( is_singular( 'post' ) && has_post_thumbnail() ) {
		$image = get_post_thumbnail_id();
	}
	return $image;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top