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.)

  • Yes, that is correct :-) – Matt Royal Jun 30 '14 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. – Nicolai Jun 30 '14 at 12:15
  • @ialocin Thanks for suggestion. However, that seems over-complicated to me ;( – Atthapon Junpun-eak Jun 30 '14 at 15:26
  • @MattRoyal Hey, are you really ok with just removing "-150x150" suffix? lol – Atthapon Junpun-eak Jun 30 '14 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 '14 at 15:57
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.

  • Thanks for your explanation. This really confirms my thought about removing dimension suffix. Marked as answer though. ;) – Atthapon Junpun-eak Jun 30 '14 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.