Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

get_intermediate_image_sizes

Function Description:

Gets the available intermediate image size names.

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 and display all intermediate image sizes
$image_sizes = get_intermediate_image_sizes();
foreach ($image_sizes as $size) {
    echo $size . '
'; }
// Example 2: Check if a specific image size exists before using it
$image_size = 'medium';
$image_sizes = get_intermediate_image_sizes();
if (in_array($image_size, $image_sizes)) {
    // Use the image size in your code
    echo 'Image size exists: ' . $image_size;
} else {
    // Handle the case where the image size doesn't exist
    echo 'Image size does not exist';
}
// Example 3: Get the URL of a specific image size for a post thumbnail
$post_thumbnail_id = get_post_thumbnail_id($post_id);
if ($post_thumbnail_id) {
    $image_url = wp_get_attachment_image_url($post_thumbnail_id, 'large');
    echo 'URL of large size image: ' . $image_url;
} else {
    echo 'Post has no thumbnail';
}