To get another URL from the onSelect Callback.
Before I had this:
1 2 3 4 | function onSelectImage( media ) { props.setAttributes( { mediaURL: media.url } ); props.setAttributes( { mediaID: media.id } ); } |
Then I console logged the media parameter, where I could find the different size URLs, so I changed it to this for my use:
1 2 3 4 5 6 7 8 9 10 11 12 13 | function onSelectImage( media ) { console.log(media); var url; if (media.sizes.medium.url) { url = media.sizes.medium.url; } else if (media.sizes.thumbnail.url) { url = media.sizes.thumbnail.url; } else { url = media.url; } props.setAttributes( { mediaURL: url } ); props.setAttributes( { mediaID: media.id } ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.