Overrides::add_amp_img_src( array $data, string $template )
Summary
Add AMP Img Src
Description
Adds ‘image_src’ to the data passed to the product featured image template.
Parameters
- $data
-
(array) (Required) Data to be sent to the template.
- $template
-
(string) (Required) Current template.
Return
(array)
Source
File: src/BigCommerce/Amp/Overrides.php
public function add_amp_img_src( $data, $template ) { if ( 'components/products/product-featured-image.php' === $template ) { $featured_image = wp_get_attachment_image_src( $data['attachment_id'], Image_Sizes::BC_MEDIUM ); if ( $featured_image ) { $data['image_src'] = wp_get_attachment_image_src( $data['attachment_id'], Image_Sizes::BC_MEDIUM ); $data['image_srcset'] = [ $data['image_src'][0] . ' ' . $data['image_src'][1] . 'w', ]; } else { $url = bigcommerce()->container()[ Assets::PATH ] . '/img/public/'; $data['image_srcset'] = [ esc_url( $url . 'bc-product-placeholder.jpg' ) . ' 2x', esc_url( $url . 'bc-product-placeholder--large.jpg' ) . ' 600w', esc_url( $url . 'bc-product-placeholder--medium.jpg' ) . ' 370w', esc_url( $url . 'bc-product-placeholder--small.jpg' ) . ' 270w', ]; $data['image_src'] = array( trailingslashit( $url ) . 'bc-product-placeholder--medium.jpg', 370, 370, ); } } return $data; }