0

Supposing that we know nothing except the url of image (smaller size e.g. 150x150)

http://xxx.com/wp-content/uploads/2014/06/test-image-150x150.jpg

What is the best way to get its full-size image url from the url above?

or

Just easily remove the prefix "-150x150" ? (I'm not sure if this is proper since i need best practice also.)

7
  • Yes, that is correct :-)
    – Matt Royal
    Jun 30, 2014 at 11:39
  • You can get the ID from the URL by using the method shown here. After you have the ID available you can use it get the information you want. Jun 30, 2014 at 12:15
  • @ialocin Thanks for suggestion. However, that seems over-complicated to me ;( Jun 30, 2014 at 15:26
  • @MattRoyal Hey, are you really ok with just removing "-150x150" suffix? lol Jun 30, 2014 at 15:27
  • @AtthaponJunpun-eak, seeing as though the URL is always appended using that convention, I have never had a problem with it ;-)
    – Matt Royal
    Jun 30, 2014 at 15:57

1 Answer 1

1

The URL for rezied images in WordPress is constructed in a way that's impossible to direct reverse. Therefore, it's impossible to get the attachment associated with a URL of a resized image with 100% certainty, unless you loop through all attachments and check whether their URL matches the given URL. However, this approach is very slow and resource-intensive.

In any normal WordPress setup, you can rest assured that, given a URL of a resized image, you can retrieve the full image URL by removing the dimensions from the URL. This is, however strange it may seem, best practice.

1
  • Thanks for your explanation. This really confirms my thought about removing dimension suffix. Marked as answer though. ;) Jun 30, 2014 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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