wc_placeholder_img() WC 1.0
Get the placeholder image.
Uses wp_get_attachment_image if using an attachment ID @since 3.6.0 to handle responsiveness.
Hooks from the function
Return
String.
Usage
wc_placeholder_img( $size, $attr );
- $size(string)
- Image size.
- $attr(string|array)
- Attributes for the image markup.
Default: ''
Code of wc_placeholder_img() wc placeholder img WC 5.0.0
function wc_placeholder_img( $size = 'woocommerce_thumbnail', $attr = '' ) {
$dimensions = wc_get_image_size( $size );
$placeholder_image = get_option( 'woocommerce_placeholder_image', 0 );
$default_attr = array(
'class' => 'woocommerce-placeholder wp-post-image',
'alt' => __( 'Placeholder', 'woocommerce' ),
);
$attr = wp_parse_args( $attr, $default_attr );
if ( wp_attachment_is_image( $placeholder_image ) ) {
$image_html = wp_get_attachment_image(
$placeholder_image,
$size,
false,
$attr
);
} else {
$image = wc_placeholder_img_src( $size );
$hwstring = image_hwstring( $dimensions['width'], $dimensions['height'] );
$attributes = array();
foreach ( $attr as $name => $value ) {
$attribute[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
$image_html = '<img src="' . esc_url( $image ) . '" ' . $hwstring . implode( ' ', $attribute ) . '/>';
}
return apply_filters( 'woocommerce_placeholder_img', $image_html, $size, $dimensions );
}