wc_placeholder_img( string $size = 'woocommerce_thumbnail', string|array $attr = '' )

Get the placeholder image.


Description Description

Uses wp_get_attachment_image if using an attachment ID @since 3.6.0 to handle responsiveness.


Parameters Parameters

$size

(Optional) Image size.

Default value: 'woocommerce_thumbnail'

$attr

(Optional) Attributes for the image markup.

Default value: ''


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-product-functions.php

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 );
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.