woocommerce_get_alt_from_product_title_and_position()
Get alt text based on product name and image position in gallery.
No Hooks.
Return
String
. Alt text.
Usage
woocommerce_get_alt_from_product_title_and_position( $product_name, $main_image, $image_index );
- $product_name(string) (required)
- Product name.
- $main_image(true|false) (required)
- Is this the main image or a thumbnail?.
- $image_index(int) (required)
- Image position in gallery.
Changelog
Since 9.3.3 | Introduced. |
woocommerce_get_alt_from_product_title_and_position() woocommerce get alt from product title and position code WC 9.5.1
function woocommerce_get_alt_from_product_title_and_position( $product_name, $main_image, $image_index ) { if ( -1 === $image_index ) { return $product_name; } $adder = $main_image ? 1 : 2; /* translators: 1: product name 2: image position */ return sprintf( __( '%1$s - Image %2$s', 'woocommerce' ), $product_name, ( $image_index + $adder ) ); }