In Genesis, by default the featured image is set to be displayed inside div.entry-content
on the archives (if image display is enabled in the theme settings).
Looking to move the featured image (link) out of .entry-content
so it is directly underneath .entry
as its first child?
While the tutorial has been written for Genesis Sample, it should work with a few adjustments in any Genesis theme.
Method 1:
This is the easier and recommended method.
We simply remove the featured image from entry content and add it above the entry header using remove_action
and add_action
.
Add the following in child theme’s functions.php:
add_action( 'genesis_before_entry', 'custom_relocate_featured_image' );
function custom_relocate_featured_image() {
// if this is not an archive, abort.
if ( is_singular() ) {
return;
}
// Remove featured image from entry content.
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
// Add featured image above entry header.
add_action( 'genesis_entry_header', 'genesis_do_post_image', 3 );
}
Method 2:
- Remove the featured image from its default location i.e., entry content.
- In a function hooked to the dynamic
genesis_markup_entry_open
filter, append the output ofgenesis_do_post_image()
.
Add the following in child theme’s functions.php:
// Remove featured image from entry content.
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_filter( 'genesis_markup_entry_open', 'insert_html_after_entry_markup', 10, 2 );
/**
* Appends HTML to the opening markup for .entry.
*
* @param string $open_html HTML tag being processed by the API.
* @param array $args Array with markup arguments.
*
* @return string
*/
function insert_html_after_entry_markup( $open_html, $args ) {
if ( ! is_singular() && $open_html ) {
ob_start();
genesis_do_post_image();
$additional_html = ob_get_clean();
$open_html = $open_html . $additional_html;
}
return $open_html;
}