Function and usage of get_intermediate_image_sizes() in wordpress


Answers ( 1 )


    get_intermediate_image_sizes() is a function in WordPress that retrieves the names of all available intermediate image sizes. Intermediate image sizes in WordPress are those sizes that are in-between the original size of the image and the thumbnail. These sizes are typically used to create versions of an image that are optimized for various places on a website, like posts, pages, or widgets.


    get_intermediate_image_sizes(): string[]


    • Purpose: This function is used to get a list of all the intermediate image sizes that are registered in a WordPress site.
    • Usage: It is often used by theme and plugin developers to fetch the names of all available image sizes, so they can work with or modify these sizes as per the requirements of their theme or plugin.


    • Type: string[]
    • Description: The function returns an array of strings. Each string in the array is the name of an available intermediate image size.

    Sample Usage:

    Here's a simple example of how you might use get_intermediate_image_sizes() in a WordPress theme or plugin:

    // Get all intermediate image sizes
    $image_sizes = get_intermediate_image_sizes();
    // Output the names of available sizes
    foreach ( $image_sizes as $size ) {
        echo $size . '<br>';

    In this example, the get_intermediate_image_sizes() function is called to retrieve all the intermediate image sizes. Then, a foreach loop is used to iterate through the array and print out each size name. This could be useful, for instance, if you're creating a settings page in your theme or plugin and you want to give users the option to select from among these sizes.

Leave an answer