Opens in a new tab
  1. Home
  2. Guides
  3. Utilities
Utilities guide

Finding a specific WordPress image size’s URL

Learn how to retrieve the exact URL of a WordPress image size, inspect generated attachment metadata, identify missing derivatives and find image URLs directly from the Media Library.

  • Updated September 2, 2026
  • 19 min read
  • WordPress guide

Finding the URL of a specific WordPress image size can be surprisingly useful when debugging themes, checking responsive images, building custom templates, testing regenerated thumbnails or confirming exactly which derivative WordPress created for an attachment.

When you upload one image to WordPress, the Media Library can represent several different physical files:

photo.jpg
photo-150x150.jpg
photo-300x200.jpg
photo-768x512.jpg
photo-1024x683.jpg

Each file can have its own URL.

The difficult part is that the WordPress Media Library normally focuses on the attachment itself rather than presenting a convenient list of every generated image size and its corresponding URL.

Developers therefore often need to retrieve a specific image size programmatically or inspect attachment metadata to find the exact generated file.

This guide explains how to find a specific WordPress image size’s URL using WordPress functions, attachment metadata, WP-CLI and the Media Library, while also covering an important distinction between a registered image size and a size that actually exists for a particular image.

Why one WordPress image can have several URLs

WordPress does not necessarily serve the original uploaded image everywhere.

If you upload:

landscape.jpg
2400 × 1600

WordPress may create several intermediate files.

For example:

landscape-150x150.jpg
landscape-300x200.jpg
landscape-768x512.jpg
landscape-1024x683.jpg

The original might be available at:

https://example.com/wp-content/uploads/2026/08/landscape.jpg

while the medium version could be:

https://example.com/wp-content/uploads/2026/08/landscape-300x200.jpg

and another generated size could use another URL entirely.

To understand where those files come from, read How WordPress generates image sizes.

Registered image sizes vs. generated image sizes

This is the most important distinction in this guide.

A WordPress image size can be:

registered on the site

without:

existing for every attachment

Those are different things.

A registered image size

A theme might register:

add_image_size(
    'hero-large',
    1600,
    900,
    true
);

This tells WordPress that a size named:

hero-large

should use:

1600 × 900

with cropping enabled.

A generated image size

A specific attachment has that size only if WordPress actually generated a corresponding derivative for it.

If the uploaded source is only:

600 × 400

a 1600-pixel derivative will normally not be created simply because the size is registered.

So:

size registered
≠
file exists for this attachment

The easiest PHP method: wp_get_attachment_image_url()

If you know the attachment ID and image size name, the simplest WordPress function is:

wp_get_attachment_image_url()

The official wp_get_attachment_image_url() documentation defines it as a function that returns the URL of an image attachment for a requested size.

Basic example

$url = wp_get_attachment_image_url(
    123,
    'medium'
);

if ( $url ) {
    echo esc_url( $url );
}

Here:

123

is the attachment ID and:

medium

is the requested image size.

The result might be:

https://example.com/wp-content/uploads/2026/08/photo-300x200.jpg

Finding a custom image size URL

The same function works with named custom image sizes.

Suppose your theme registers:

add_image_size(
    'homepage-card',
    640,
    420,
    true
);

You can request:

$url = wp_get_attachment_image_url(
    123,
    'homepage-card'
);

Then use it safely:

if ( $url ) {
    echo esc_url( $url );
}

If the requested derivative is available, the resulting URL might look like:

https://example.com/wp-content/uploads/2026/08/photo-640x420.jpg

Finding the full-size image URL

To request the full-size attachment image:

$url = wp_get_attachment_image_url(
    123,
    'full'
);

Do not manually remove:

-300x200

from a URL and assume the resulting filename is always the correct full attachment.

WordPress can apply large-image scaling and other media processing, so using its API is safer than reconstructing filenames manually.

Using wp_get_attachment_image_src()

Sometimes you need more than the URL.

The function:

wp_get_attachment_image_src()

returns an array containing:

  • the URL;
  • width;
  • height;
  • whether the returned image is an intermediate resized image.

The official wp_get_attachment_image_src() documentation documents this return structure.

Example

$image = wp_get_attachment_image_src(
    123,
    'medium'
);

if ( $image ) {

    $url    = $image[0];
    $width  = $image[1];
    $height = $image[2];
    $resized = $image[3];

}

Conceptually, the result can look like:

array(
    'https://example.com/uploads/photo-300x200.jpg',
    300,
    200,
    true
)

Why the fourth value matters

The final boolean tells you whether the returned result is an intermediate resized image.

That can help when debugging cases where you requested a size but WordPress returned another usable image representation.

wp_get_attachment_image_url() is a convenience wrapper

Internally, wp_get_attachment_image_url() uses:

wp_get_attachment_image_src()

and returns the first element of the resulting array.

In simple terms:

wp_get_attachment_image_src()
↓
URL + width + height + resized flag

wp_get_attachment_image_url()
↓
URL only

Use the shorter function when you only need the address.

Use the full source function when you are debugging dimensions or resize behavior.

Important: requesting a URL is not always proof that the requested derivative exists

This is a subtle but important WordPress behavior.

If you ask for an image size that cannot be resolved exactly, WordPress may still return a usable attachment image in some circumstances rather than giving you a simple statement that:

this exact derivative exists

For example, the documentation for wp_get_attachment_image_url() notes that if the requested size does not match a registered image size, the original image URL can be returned.

Therefore:

$url !== false

does not necessarily prove:

the exact named thumbnail file
was generated

If you need that level of certainty, inspect the intermediate-size metadata directly.

Using image_get_intermediate_size()

For precise inspection of a generated intermediate size, WordPress provides:

image_get_intermediate_size()

The official image_get_intermediate_size() documentation explains that the function retrieves the resized image’s path, width and height and can also provide the URL when a registered size name is requested.

Example

$image = image_get_intermediate_size(
    123,
    'medium'
);

if ( $image ) {

    $url = $image['url'];

    echo esc_url( $url );

}

The returned array can contain information such as:

file
width
height
path
url

Example result

array(
    'file'   => 'photo-300x200.jpg',
    'width'  => 300,
    'height' => 200,
    'path'   => '2026/08/photo-300x200.jpg',
    'url'    => 'https://example.com/wp-content/uploads/2026/08/photo-300x200.jpg'
)

This makes the function particularly useful when you want to determine whether a specific intermediate file exists in the attachment metadata.

When image_get_intermediate_size() returns false

If the requested intermediate size cannot be found, the function can return:

false

That can happen because:

  • the derivative was never generated;
  • the image was uploaded before that size existed;
  • the original image is too small;
  • generation failed;
  • the attachment metadata is incomplete;
  • the requested size name is wrong.

If an expected size is missing from older images, see Regenerating WordPress image thumbnails.

Inspecting attachment metadata directly

Another useful method is:

wp_get_attachment_metadata()

The official wp_get_attachment_metadata() documentation describes the metadata WordPress stores for an attachment.

Example

$metadata = wp_get_attachment_metadata(
    123
);

For an image, the resulting structure can contain:

width
height
file
sizes
image_meta

The sizes array

The part we care about is commonly:

$metadata['sizes']

Conceptually:

array(
    'thumbnail' => array(
        'file'   => 'photo-150x150.jpg',
        'width'  => 150,
        'height' => 150,
    ),

    'medium' => array(
        'file'   => 'photo-300x200.jpg',
        'width'  => 300,
        'height' => 200,
    ),
)

This tells you which generated sizes WordPress has recorded for the attachment.

Checking whether a named image size exists in metadata

You can explicitly test:

$metadata = wp_get_attachment_metadata(
    123
);

if (
    isset(
        $metadata['sizes']['medium']
    )
) {
    // The size is present in metadata.
}

For a custom size:

if (
    isset(
        $metadata['sizes']['homepage-card']
    )
) {
    // homepage-card exists in metadata.
}

This is much more precise than trying to guess filenames from dimensions.

Why you should not construct image URLs manually

You might be tempted to take:

photo.jpg

and turn it into:

photo-300x200.jpg

manually.

Avoid relying on this.

The actual dimensions may differ

A registered size of:

300 × 300

with proportional resizing does not guarantee the output is:

300 × 300

A landscape image might instead become:

300 × 200

The filename may not exist

A registered size does not guarantee the derivative was generated.

Filters can alter generation

Plugins and themes can modify which intermediate sizes WordPress creates.

Large-image handling can change the source relationship

The file WordPress considers the working full-size image may not always correspond to the assumptions in a manually constructed URL.

Use the media APIs instead.

How to find the attachment ID

Most WordPress image functions expect an attachment ID.

If you already have one:

123

the rest is straightforward.

But sometimes you begin only with an image displayed on the frontend.

From the Media Library

Open:

Media
→
Library

then select or edit the image.

Depending on the admin screen, the attachment ID can usually be determined from the edit URL or attachment data.

Inside a template

If you are working with a featured image:

$attachment_id = get_post_thumbnail_id(
    get_the_ID()
);

Then:

$url = wp_get_attachment_image_url(
    $attachment_id,
    'medium'
);

Finding a featured image’s specific size URL

A complete example:

$attachment_id = get_post_thumbnail_id();

if ( $attachment_id ) {

    $url = wp_get_attachment_image_url(
        $attachment_id,
        'large'
    );

    if ( $url ) {
        echo esc_url( $url );
    }

}

This is useful when building:

  • custom cards;
  • hero sections;
  • Open Graph integrations;
  • structured data;
  • custom API responses.

Finding an image URL from a custom field

Custom fields can store images in several formats depending on the plugin or implementation.

A field might contain:

attachment ID

or:

full URL

or:

attachment array

If you have the attachment ID, use WordPress’s media functions.

For example:

$attachment_id = 123;

$card_url = wp_get_attachment_image_url(
    $attachment_id,
    'homepage-card'
);

It is preferable to store and work from the attachment ID when you need access to WordPress-generated image variants.

Finding the URL with TheOneWP Image Sizes List

If the goal is simply:

I have an image in the Media Library
and I need the URL of one generated size

writing PHP every time is unnecessary.

TheOneWP Image Sizes List adds an image-size panel directly to attachment details.

The module reads the sizes actually generated for that specific image rather than merely displaying every size registered globally on the website.

The panel displays

  • the generated image size;
  • its actual dimensions;
  • a direct link;
  • a copy-to-clipboard control for the URL.

It appears in both:

  • the classic attachment edit screen;
  • the Media Library grid-view attachment modal.

Why per-image data matters

Suppose the site registers:

thumbnail
medium
medium_large
large
homepage-card
hero-large

but a particular image actually has only:

thumbnail
medium
homepage-card

The useful question is not:

What sizes can this website generate?

It is:

What sizes actually exist
for this attachment?

The module answers the second question.

How to find a size URL from the Media Library with TheOneWP

The workflow is straightforward.

1. Enable Image Sizes List

Enable Image Sizes List from TheOneWP settings.

2. Open an image

Go to:

Media
→
Library

and select an image.

3. Inspect the generated-size panel

The panel lists the image variants that actually exist for that attachment.

4. Open or copy the URL

Use the direct link to inspect the file or copy its URL for use elsewhere.

This is particularly useful after regenerating image thumbnails, because you can immediately confirm whether the expected derivative exists.

Finding all globally registered image sizes

Sometimes you do not know the size name yet.

In that case, first determine what image sizes the website currently registers.

WP-CLI provides:

wp media image-size

The official wp media image-size documentation explains that the command lists image sizes registered with WordPress.

Example output

+----------------+-------+--------+-------+
| name           | width | height | crop  |
+----------------+-------+--------+-------+
| full           |       |        | N/A   |
| large          | 1024  | 1024   | soft  |
| medium_large   | 768   | 0      | soft  |
| medium         | 300   | 300    | soft  |
| thumbnail      | 150   | 150    | hard  |
| homepage-card  | 640   | 420    | hard  |
+----------------+-------+--------+-------+

This answers:

What sizes are registered?

It does not answer:

Which of those sizes exist
for attachment 123?

For that, inspect the attachment metadata or use the per-image interface described above.

Registered size list vs. attachment size list

These two lists solve different problems.

Registered sizes

Tell you what WordPress, the current theme and plugins are configured to generate.

Example:

thumbnail
medium
large
card
hero

Attachment metadata

Tells you what was actually generated for one particular image.

Example:

thumbnail
medium
card

The difference can expose several problems:

  • old attachments uploaded before a custom size was added;
  • source images that were too small;
  • failed image processing;
  • incomplete migrations;
  • missing regenerated thumbnails.

Finding a specific URL after thumbnail regeneration

Suppose you add:

add_image_size(
    'portfolio-card',
    800,
    600,
    true
);

and then regenerate an old attachment.

Do not assume the operation worked simply because the regeneration process completed.

Check programmatically

$size = image_get_intermediate_size(
    123,
    'portfolio-card'
);

if ( $size ) {
    echo esc_url(
        $size['url']
    );
}

Or check visually

Open the attachment through Image Sizes List and confirm that:

portfolio-card

appears in its generated-size list.

For the full regeneration workflow, see Regenerating WordPress image thumbnails.

Why a requested WordPress image size may be missing

If you cannot find the expected URL, several explanations are possible.

The image was uploaded before the size existed

Suppose:

image uploaded:
2023

custom size added:
2026

The existing image does not automatically gain that new derivative.

Regeneration may be required.

The source image is too small

If the registered size is:

1200 × 800

and the source is:

500 × 300

that derivative may not exist.

The image processor failed

Server-side processing can fail because of:

  • memory limits;
  • unsupported formats;
  • damaged source files;
  • GD or Imagick errors;
  • filesystem permissions.

A plugin filtered the size out

The list of sizes generated for an attachment can be filtered.

For example, WordPress exposes:

intermediate_image_sizes_advanced

which can alter the image sizes generated for an upload.

The size name is wrong

This:

homepage_card

is not the same handle as:

homepage-card

Check the actual registered name.

Finding dimensions when you have the URL

If you already have a WordPress image URL such as:

photo-640x420.jpg

the filename suggests the generated dimensions.

But do not rely exclusively on filename parsing in application logic.

WordPress already stores width and height in attachment metadata.

Use:

wp_get_attachment_image_src()

or:

image_get_intermediate_size()

to retrieve authoritative metadata associated with the attachment.

Finding an attachment size inside srcset

On the frontend, WordPress often generates responsive markup containing:

srcset

For example:

<img
    src="photo-768x512.jpg"
    srcset="
        photo-300x200.jpg 300w,
        photo-768x512.jpg 768w,
        photo-1024x683.jpg 1024w
    "
    sizes="(max-width: 768px) 100vw, 768px"
    alt=""
>

You can inspect this markup in browser developer tools to discover URLs WordPress is currently presenting as responsive candidates.

But srcset is not a complete generated-size inventory

A generated derivative may exist without appearing in one particular srcset.

WordPress considers factors such as:

  • aspect ratio;
  • requested image size;
  • available metadata;
  • responsive-image calculations.

Therefore, inspecting srcset is useful for frontend debugging, but attachment metadata is better when you need the full per-image inventory.

Do not confuse the attachment URL with an image-size URL

The function:

wp_get_attachment_url()

returns the attachment file URL.

It does not accept an image-size parameter.

For example:

$url = wp_get_attachment_url(
    123
);

is different from:

$url = wp_get_attachment_image_url(
    123,
    'medium'
);

The difference

wp_get_attachment_url()
→ attachment file

wp_get_attachment_image_url()
→ image representation for requested size

Use the second function when the specific WordPress image size matters.

Do not hardcode generated thumbnail URLs in templates

Avoid this:

$url =
    '/wp-content/uploads/2026/08/'
    . 'photo-640x420.jpg';

This assumes too much.

The site’s:

  • domain;
  • uploads path;
  • filename;
  • generated dimensions;
  • media configuration

can all differ.

Prefer:

$url = wp_get_attachment_image_url(
    $attachment_id,
    'homepage-card'
);

Do not store generated size URLs when an attachment ID is enough

If you are designing a custom WordPress feature, storing:

attachment ID: 123

is often more flexible than storing:

https://example.com/uploads/photo-640x420.jpg

Why?

Because from the attachment ID you can later request:

thumbnail
medium
large
homepage-card
hero
full

without changing the stored reference.

A hardcoded derivative URL is tied to one specific generated file.

Image URL changes and caching

Different WordPress image sizes normally use different filenames.

For example:

photo-300x200.jpg

photo-640x420.jpg

These are separate cache keys because they are separate URLs.

However, media workflows that replace content while retaining the same URL introduce another issue: browsers and CDNs may continue serving cached data.

That problem is explained in WordPress image cache-busting explained.

Debugging the wrong image size on the frontend

If a page appears to be loading the wrong image, do not immediately assume WordPress generated the wrong thumbnail.

Work through the chain systematically.

1. Find the attachment ID

Identify the Media Library attachment being used.

2. Check registered sizes

wp media image-size

3. Check which sizes exist for that attachment

Use:

image_get_intermediate_size()

attachment metadata or Image Sizes List.

4. Inspect the template request

Check whether the theme requests:

medium

when you expected:

homepage-card

5. Inspect frontend markup

Review:

src
srcset
sizes

6. Inspect the Network panel

Confirm which physical URL the browser actually downloads.

The HTML source and the downloaded resource are not always identical in responsive-image scenarios because the browser can choose from srcset.

A useful debugging helper

During development, you can temporarily inspect all generated sizes for an attachment:

$metadata = wp_get_attachment_metadata(
    123
);

if (
    ! empty(
        $metadata['sizes']
    )
) {
    echo '<pre>';
    print_r(
        $metadata['sizes']
    );
    echo '</pre>';
}

Do not leave raw debugging output exposed on a production frontend.

This is intended only as a development technique.

Finding every generated size URL programmatically

If you need more than one named size, you can work from the attachment metadata.

The metadata provides filenames, while the attachment upload directory provides the base location.

For many applications, however, querying each known size through WordPress’s image API is easier and safer.

For example:

$sizes = array(
    'thumbnail',
    'medium',
    'large',
    'homepage-card',
);

foreach ( $sizes as $size ) {

    $image =
        image_get_intermediate_size(
            123,
            $size
        );

    if ( $image ) {

        echo esc_html( $size );
        echo ': ';
        echo esc_url(
            $image['url']
        );

    }
}

This checks the attachment rather than guessing which files should theoretically exist.

Which method should you use?

If you only need a URL in PHP

Use:

wp_get_attachment_image_url()

If you need URL and dimensions

Use:

wp_get_attachment_image_src()

If you want to inspect a specific generated intermediate size

Use:

image_get_intermediate_size()

If you want the complete attachment metadata

Use:

wp_get_attachment_metadata()

If you want to know every size registered globally

Use:

wp media image-size

If you want to copy URLs visually from wp-admin

Use TheOneWP Image Sizes List.

Common mistakes when finding WordPress image size URLs

Guessing the filename from dimensions

Use WordPress metadata instead.

Assuming every registered size exists

A site-wide registration does not guarantee a per-image derivative.

Using wp_get_attachment_url() for a specific image size

Use wp_get_attachment_image_url().

Assuming any returned URL proves the exact requested derivative exists

Use image_get_intermediate_size() or attachment metadata when exact existence matters.

Looking only at srcset

srcset represents responsive candidates for a particular output context, not necessarily every file stored for the attachment.

Assuming a missing custom size means WordPress is broken

The original may simply be too small or may predate the registered size.

Forgetting to regenerate older attachments

Newly registered image sizes do not retroactively appear for old media without regeneration.

Hardcoding wp-content/uploads

WordPress installations can use custom upload configurations.

Hardcoding generated URLs into reusable code

Store attachment IDs and let WordPress resolve the appropriate file.

Confusing image generation with caching

A correct file can exist while an old cached resource is still displayed.

WordPress image size URL checklist

  • Identify the attachment ID.
  • Identify the registered image-size name.
  • Use wp_get_attachment_image_url() when only the URL is required.
  • Use wp_get_attachment_image_src() when dimensions are also useful.
  • Use image_get_intermediate_size() when exact generated-size metadata matters.
  • Use wp_get_attachment_metadata() to inspect all stored attachment metadata.
  • Do not guess generated filenames.
  • Do not assume all registered sizes exist for every image.
  • Check the source dimensions when a derivative is missing.
  • Check whether the attachment predates the image-size registration.
  • Regenerate old images when a required size is missing.
  • Use wp media image-size to inspect global registrations.
  • Inspect srcset when debugging responsive output.
  • Check the browser Network panel to see what was actually downloaded.
  • Use attachment IDs instead of hardcoded derivative URLs where possible.
  • Account for caching when a URL is reused after media replacement.

Related WordPress media guides

Continue with these related guides and tools:

Final thoughts

Finding a specific WordPress image size’s URL is straightforward once you distinguish between the site’s global image-size configuration and the files actually generated for an individual attachment.

The basic relationship is:

registered image size
↓
WordPress attempts generation
↓
attachment metadata records
successful derivative
↓
WordPress API resolves its URL

If you only need a URL inside PHP, wp_get_attachment_image_url() is usually the simplest solution.

If you also need dimensions and resize information, use wp_get_attachment_image_src().

If you are debugging whether a specific intermediate file really exists for the attachment, image_get_intermediate_size() or wp_get_attachment_metadata() provides more precise information.

For wp-admin workflows, TheOneWP Image Sizes List removes the need to inspect metadata manually by showing every derivative actually generated for an image together with its dimensions, direct URL and copy control.

Most importantly, do not construct thumbnail URLs from filenames or assume that every globally registered image size exists for every upload. Let WordPress’s media metadata tell you what was really generated.

Simplify your WordPress stack

A modular WordPress toolkit. 104 focused tools.

Ultimately, you can build cleaner workflows, maintain fewer plugins and enable only the features each website actually needs.