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: Retrieve 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 given attachment ID
$attachment_id = 456;
$desired_size = 'medium';
$image_sizes = wp_get_attachment_image_sizes( $attachment_id );
if ( in_array( $desired_size, $image_sizes ) ) {
echo 'The size ' . $desired_size . ' exists for attachment ID: ' . $attachment_id;
} else {
echo 'The size ' . $desired_size . ' does not exist for attachment ID: ' . $attachment_id;
}
// Example 3: Get the URL of an image in a specific size for a given attachment ID
$attachment_id = 789;
$desired_size = 'large';
$image_url = wp_get_attachment_image_url( $attachment_id, $desired_size );
if ( $image_url ) {
echo 'The URL of the image in size ' . $desired_size . ' is: ' . $image_url;
} else {
echo 'No image found for attachment ID: ' . $attachment_id . ' in size ' . $desired_size;
}