# Image Sizes REST Endpoint for Headless Front Ends

> Adds a public /wp-json/site/v1/image-sizes endpoint listing every registered image size with its width, height and crop setting, so headless front ends can pick the right size for each layout.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: rest-api, image-sizes, headless
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/rest-image-sizes-endpoint/

## Code

```php
add_action( 'rest_api_init', function () {
    register_rest_route( 'site/v1', '/image-sizes', array(
        'methods'             => WP_REST_Server::READABLE,
        'permission_callback' => '__return_true',
        'callback'            => function () {
            $sizes = array();
            foreach ( wp_get_registered_image_subsizes() as $name => $size ) {
                $sizes[] = array(
                    'name'   => $name,
                    'width'  => (int) $size['width'],
                    'height' => (int) $size['height'],
                    'crop'   => is_array( $size['crop'] ) ? $size['crop'] : (bool) $size['crop'],
                );
            }
            $response = new WP_REST_Response( $sizes );
            $response->header( 'Cache-Control', 'public, max-age=86400' );
            return $response;
        },
    ) );
} );
```

## Notes

Read-only and cached by browsers for a day; sizes added by themes and plugins are included.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Image Sizes REST Endpoint for Headless Front Ends" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
