Function Signature:
wp_get_attachment_image_sizes
Function Description:
Function Examples:
⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Get all available image sizes for a specific attachment ID
$attachment_id = 123;
$image_sizes = wp_get_attachment_image_sizes( $attachment_id );
if ( $image_sizes ) {
foreach ( $image_sizes as $size ) {
echo $size . '
';
}
} else {
echo 'No image sizes found for attachment ID: ' . $attachment_id;
}
// Example 2: Check if a specific image size exists for a particular attachment ID
$attachment_id = 456;
$size_to_check = 'medium';
$image_sizes = wp_get_attachment_image_sizes( $attachment_id );
if ( in_array( $size_to_check, $image_sizes ) ) {
echo 'Image size ' . $size_to_check . ' exists for attachment ID: ' . $attachment_id;
} else {
echo 'Image size ' . $size_to_check . ' does not exist for attachment ID: ' . $attachment_id;
}
// Example 3: Get all image sizes for a specific attachment ID and display the corresponding image tags
$attachment_id = 789;
$image_sizes = wp_get_attachment_image_sizes( $attachment_id );
if ( $image_sizes ) {
foreach ( $image_sizes as $size ) {
$image_tag = wp_get_attachment_image( $attachment_id, $size );
echo $image_tag . '
';
}
} else {
echo 'No image sizes found for attachment ID: ' . $attachment_id;
}