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);
foreach ($image_sizes as $size => $size_data) {
echo "Size: $size, Width: {$size_data['width']}, Height: {$size_data['height']}\n";
}
// Example 2: Check if a specific image size exists for a given attachment ID
$attachment_id = 456;
$size_to_check = 'thumbnail';
$image_sizes = wp_get_attachment_image_sizes($attachment_id);
if (isset($image_sizes[$size_to_check])) {
echo "The '$size_to_check' size exists for attachment $attachment_id";
} else {
echo "The '$size_to_check' size does not exist for attachment $attachment_id";
}
// Example 3: Retrieve the URL of a specific image size for a given attachment ID
$attachment_id = 789;
$size_to_get = 'medium';
$image_sizes = wp_get_attachment_image_sizes($attachment_id);
if (isset($image_sizes[$size_to_get])) {
$image_url = wp_get_attachment_image_url($attachment_id, $size_to_get);
echo "The URL of the '$size_to_get' size for attachment $attachment_id is: $image_url";
} else {
echo "The '$size_to_get' size does not exist for attachment $attachment_id";
}