MainWP Community

Use WooCommerce thumbnail for header element background in GeneratePress

Use WooCommerce thumbnail for header element background in GeneratePress on your child site.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'generate_page_hero_background_image_url', function( $url ) {
    
    if ( ! function_exists( 'get_woocommerce_term_meta' ) ) {
        return $url;
    }

    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
    $background_image = wp_get_attachment_url( $thumbnail_id );

    if ( $background_image ) {
        $url = $background_image;
    }

    return $url;
});
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.