Want to add featured image below content on single post pages in Genesis?
Create a file named single-post.php in your child theme directory having the following code:
<?php
add_action( 'genesis_before_entry_content', 'custom_featured_image' );
/**
* Show featured image (if present) before content on single posts.
*/
function custom_featured_image() {
// if there is no featured image, abort.
if ( ! has_post_thumbnail() ) {
return;
}
printf( '<figure><img src="%s" alt="%s" /></figure>', genesis_get_image( 'format=url&size=medium_large' ), the_title_attribute( 'echo=0' ) );
}
genesis();
Hey Sridar, thanks for another really useful post. Thanks for introducing the use of the element, not seen this before. Just looked it up at CSS Schools. I’ve got loads of sites where I add featured images on pages by using a simple function in functions.php to add featured image as an with no wrapped around it. I guess for best practice markup these should be using too?
Why the parameter ‘the_title_attribute( ‘echo=0′ )’ ? Is that to null out the title so that there is no tooltip on hovering mouse over the featured image?
I am guessing you are talking about the
figure
element.You can read about it here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure.
By default the_title_attribute() displays the title but in this case, we want it to return the title and hence
'echo=0'
. More info here: https://codex.wordpress.org/Function_Reference/the_title_attribute.Is is possible to use a Genesis Plugin to just turn this feature on or off?
You could use Advanced Custom Fields plugin to create a checkbox on options page and set it up to toggle this.
Hi, thanks for this bit of code. Is it possible to add a class to this element?