I have set up some shortcodes to make things simpler for the user. It wraps up some bootstrap markup and just lets you put the h1, some img urls, etc in it without getting too close to the markup.

What I originally wanted was to let the user upload the image through the media library and then grab the image url for the resize that I had generated. I thought this used to be in there but I can't find a way.

So assuming thats not possible, is there a way I can take a url such as http://www.devsite.co.uk/wp-content/uploads/2015/01/testupload.jpg which the user will copy paste into the shortcode and then use a WP function to get the url for the columns-thumbnail resize?

If its not built in I can just check the dimensions directly but it feels brittle to do it this way should the size change or the way WP generates filenames change in the future.

Some code:

function roots_setup() {
  // snip

  // setup image sizes
  // http://codex.wordpress.org/Function_Reference/add_image_size
  add_image_size('triple-thumbnail', 370, 222, true); // true = hard crop
  add_image_size('columns-thumbnail', 200, 200, true);

  // snip
add_action('after_setup_theme', 'roots_setup');

function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'triple-thumbnail' => __( 'Triple Header Image' ),
        'columns-thumbnail' => __( 'Columns Thumbnail' )
    ) );
add_filter( 'image_size_names_choose', 'my_custom_sizes' );

Shortcode example:

[column imageurl='http://www.example.co.uk/wp-content/uploads/2015/01/blinds-triple-vertical.jpg' title='Vertical Blinds']

Something that I'm imagining might be in WP already somewhere:

$imageurl = 'http://www.example.co.uk/wp-content/uploads/2015/01/blinds-triple-vertical.jpg';
$thumbnailurl = WP_get_image_resize_url($imageurl, 'columns-thumbnail');

Does this exist?

2 Answers 2


The images URL are direct. They are not part of WP rewrite system, they are not stored as explicit metadata, they are never used for reverse lookups in core.

It is possible to make fair attempt at reversing URL, see Turn a URL into an Attachment / Post ID.

But it's not a normal workflow or reliable. You could as well have users put attachment IDs in shortocode (possibly with a bit of helper interface) and get much more reliable code flow.


From the sizes you have added (and the image_size_names_choose filter), your use should be able to upload an image via the media library and then choose the proper image size when putting the image into their content with the media button.

When they are in the media library viewer, they should be able to click an image and then look at the lower right area of the screen to see available image sizes (a drop down if memory serves). If that isn't there, you might check the "Screen Options" setting at the top right to make sure you aren't hiding the image size options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.