Website Vidya
How-To GuidesStep-by-Step Guide

How to Display Featured Image in Genesis Child Themes

This tutorial enables you to display featured image in Genesis Child Themes . We all know that images are extremely important for enhancing the appearance of your website, and posts. It benefits you in various ways including increasing the ...

RR
Rajesh RayLead Systems Educator
Published:
5 min read
How to Display Featured Image in Genesis Child Themes
AI Executive SummaryCORE CIS AI

5 min read

This tutorial enables you to display featured image in Genesis Child Themes . We all know that images are extremely important for enhancing the appearance of your website, and posts. It benefits you in various ways including increasing the ...

Key Highlights
  • Code to Display Featured Image in Genesis Child Theme
  • Alternate Method: Display Featured Image for Genesis Plugin
Grounded in full engineering runbookCORE CIS Ai Engine

This tutorial enables you to display featured image in Genesis Child Themes. We all know that images are extremely important for enhancing the appearance of your website, and posts. It benefits you in various ways including increasing the unique visitors to your website. This is the reason the most famous and advanced CMS- WordPress has an in-built option for the featured image.

Some of you might have noticed that the featured image is not displayed on the single post of the Genesis child themes. I recently updated to the latest version of the Genesis child theme and I was surprised to see that the featured image section was no longer there.

I started exploring the StudioPress documentation section for the single post featured image. Luckily, I fixed the issue in a few minutes by copy-pasting a few lines of PHP code.

You can simply copy-paste these PHP codes in the functions.php file of your Genesis Child Theme. The code below will enable you to display the featured post image, before or after your title on single posts.

Advertisement

The PHP code below displays the featured image after the post title on a single post.

add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );

function single_post_featured_image() {
	
	if ( ! is_singular( 'post' ) )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

The PHP code below displays the featured image before the post title on a single post.

add_action( 'genesis_entry_header', 'single_post_featured_image', 5 );

function single_post_featured_image() {
	
	if ( ! is_singular( 'post' ) )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

To display the featured image on static single pages, just copy-paste the code given below:

add_action( 'genesis_entry_header', 'single_post_featured_image', 5 );

function single_post_featured_image() {
	
	if ( ! is_singular( 'page' ) )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

If you want to display featured image on both static pages and single posts, add the PHP code given below:

add_action( 'genesis_entry_header', 'single_post_featured_image', 5 );

function single_post_featured_image() {
	
	if ( ! is_singular() )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

Change Image Size

The PHP code below helps you change the size of the featured image according to your Media Settings. You can use other default sizes configured in Settings > Media.

Advertisement
  • thumbnail
  • medium
  • large
  • full
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );

function single_post_featured_image() {
if ( ! is_singular( 'post' ) )
		return;
$img = genesis_get_image( array( 'format' => 'html', 'size' => 'large', 'attr' => array( 'class' => 'post-image' ) ) );
printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	
}

To use any other custom size, use the code below:

add_image_size( 'portfolio', 540, 340, TRUE );

Using Old XHTML Loop Hooks

If you are still running XHTML, use the old Loop Hooks:

add_action( 'genesis_before_post_title', 'single_post_featured_image' );

function single_post_featured_image() {
	
	if ( ! is_singular( 'post' ) )
		return;
	
	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
	}

Space Between Title & Image

To add a margin between the title and the image you just need to add a single line code to your style.css file or custom CSS file.

.single .post-image {
margin-bottom: 20px;
}

You can adjust the margin-bottom property by increasing or decreasing its value.

Align Featured Image on Single Post

To align the featured image on the right, use the following CSS:

Advertisement
.single .post-image {
    float:right; 
    margin:0 0 1em 1em;
    width: 150px;
    height: 150px;
}

If you want to use the same styling without writing the CSS, you can use the PHP code (alignright class) inside the PHP file.

'class' => 'alignright'

To align the featured image on the left, use the following CSS:

.single .post-image {
    float:left; 
    margin: 1em 1em 0 0;
    width: 300px;
    height: 300px;
}

To execute the same without writing CSS, use the PHP code below:

'class' => 'alignleft'

To remove the link from the featured images, simply replace this code

$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );

with this:

$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
	echo $img;

Display Featured Image for Genesis Plugin is an easiest way to display featured image in Genesis Child themes. The plugin comes up with various features that help you to display lovely large and full-width images.

Features include:

  • display the featured image as a banner (screen width) image.
  • display the featured image above your post/page content.
  • display nothing if the featured image width is less than or equal to your media Setting.

All you need is to navigate to plugins » add new.

Search for "Display Featured Image for Genesis", install and activate the plugin.

You can play with the configuration settings to get featured image as screen width and large.

That's it!

I hope this would help you to display featured image in Genesis Child Themes. If you face any difficulty, ask me in the comment section below.

Topics:#wordpress
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

LE
LE
Discourse & Reader Insights (3)
LE
LezlyJun 20, 2021

So featured images doesn't work in any of the themes anymore unless you code it? Was this a move by Studio Press to get everyone to sign up for Genesis Pro at $360 a year? I sound bitter, I know. I retired a few years back & volunteered to do a site for a group I'm in & spent the morning trying to figure out why featured images doesn't work anymore. Thanks for the code. I'll give it a shot.

LE
LezlyJun 20, 2021

Unfortunately the single page code didn't work, & instead only printed the page URL above the title, but no image.

Rajesh Ray(Author reply)• Jun 28, 2021

Hi Lezly, Which StudioPress theme are you using? Let me know, I will try to fix it for you. Thanks :)

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout