Last active
September 10, 2018 08:53
-
-
Save damiencarbery/5c3a3788d46d50721eb41b3420d49cc0 to your computer and use it in GitHub Desktop.
Set header image on product pages to main product image - in Essence Pro theme. https://damiencarbery.com/2018/09/set-product-hero-image-in-essence-pro/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Product Header Image for Essence Pro | |
Plugin URI: https://damiencarbery.com/2018/09/set-product-hero-image-in-essence-pro/ | |
Description: Set the header image to a product image in Essence Pro. | |
Author: Damien Carbery | |
Version: 0.1 | |
*/ | |
// Retrieve first product image if on a product page. | |
// Use this short-circuit filter to make it quicker on product pages - if the 'genesis_get_image' | |
// filter was used then the 'genesis_get_image()' function would have unnecessarily called a | |
// number of attachment related functions (which involve database queries). | |
add_filter( 'genesis_pre_get_image', 'dcwd_get_product_header_image', 10, 3 ); | |
function dcwd_short_circuit_product_header_image( $false, $args, $post_obj ) { | |
if ( wc_get_page_id( 'shop' ) == $args['post_id'] ) { | |
if ( is_product() ) { | |
$featured_image_id = get_post_thumbnail_id( get_the_ID() ); | |
list( $image_url ) = wp_get_attachment_image_src( $featured_image_id, 'header-hero' ); | |
return $image_url; | |
} | |
} | |
return $false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment