How To Show WordPress Featured Image On Single Posts And Pages In Genesis

Featured images on posts and pages in Genesis

Featured images in WordPress play a crucial role for drawing visitor’s attention. Using featured images for posts is a good idea for enhancing the user experience.

Genesis by default allows you to enable or disable the featured images on the blog page and archives via Theme Settings. But there is no setting or option in WordPress or Genesis to allow you to display the featured images on posts or pages.

To show the featured image on posts and pages on Genesis site, add the following code to your theme’s functions.php:

add_action( 'genesis_entry_header', 'bt_enable_single_featimg', 12 );
function bt_enable_single_featimg() {
	if( is_single() || is_page() ) { // Only display on single posts and pages, update as required
		$featured_img = genesis_get_image( array(
			'post_id'	=> get_the_ID(), // will work only for singular (posts and pages) templates
			'format'	=> 'html', // Can be of type 'html', 'url' or 'src'
			'size'		=> 'full', // Can be of type 'full', 'thumbnail', 'medium', 'large' or any other size(s) if registered
			'attr'    => genesis_parse_attr( 'entry-image', array ( 'alt' => get_the_title() ) ),
		) );

		echo '<div class="featured-image">' . $featured_img . '</div>'; // Use custom markup to output the image as desired
	}
}

This code snippet displays the featured image after the entry title i.e., after the post and the page title. If you want the featured image to show before the entry title, you can update the priority for the action hook to a higher number as shown below:

add_action( 'genesis_entry_header', 'bt_enable_single_featimg', 5 ); // Displays the featured image above the post / page title; priority changed from 12 to 5

Or you can also use a completely different location / hook to display the featured image. Check out Genesis visual hook guide to see the complete list of available hook locations in Genesis. You can use one of these hooks to display the featured image.

Divi WordPress Theme