Snippets: Display Blog Post Featured Image As Page Header Background

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

// Adds your featured image to the page header
function my_blog_posts_page_header_image( $image ) {
	if ( is_singular( 'post' ) && has_post_thumbnail() ) {
		$image = get_post_thumbnail_id();
	}
	return $image;
}
add_filter( 'wpex_page_header_background_image', 'my_blog_posts_page_header_image' );

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.