Hi, Unfortunately, WordPress does not recognize intermediate images (e.g. “thumbnail”, “full”, etc.) as items in the media library. Only the original source file is seen as part of the media library, which allows caption, description, etc. data to be retrieved for it.
Thanks Archetyped,
Apologies if this sounds hacky, is there anyway that I could move my code so that it runs like the following pseudo code.
slb runs as normal on full size image.
slb retries image date for full size image.
function is run immediately before img element is generated by slb.
Any help or pointers would be great.
Davey
Hi Archetyped, thanks for your response. I’m wondering if anyone else can point me in the right direction to do this, as this is not really a support question but more of a modification.
Hope this is the correct place to ask.
Many thanks – Davey
Solved. For anyone interested in using resized images in simple lightbox this is how I got things to work.
It is a bit of a hack (edits a plugin file) so please forgive me Archetyped.
Don’t use the php function that I posted in my first post. Simply edit this file (make a backup first):
plugins/simple-lightbox/content-handlers/image/js/dev/handler.image.js
Change:
// Set attributes
item.set_attribute('dimensions', {'width': img.width, 'height': img.height});
// Build output
var out = $('<img />', {'src': item.get_uri()});
To:
// Set attributes (edited for resized image)
if(item._attr_default.sizes.large) {
// Set attributes (edited for resized image)
item.set_attribute('dimensions', {'width': item._attr_default.sizes.large.width, 'height': item._attr_default.sizes.large.height});
// Build output (edited for resized image)
var out = $('<img />', {'src': item.get_uri().replace(item._attr_default.sizes.original.file, item._attr_default.sizes.large.file)});
} else {
// Set attributes
item.set_attribute('dimensions', {'width': img.width, 'height': img.height});
// Build output
var out = $('<img />', {'src': item.get_uri()});
}
Minify and copy the contents to (make a backup first):
plugins/simple-lightbox/content-handlers/image/js/prod/handler.image.js
Don’t forget, if you update the SLB plugin your changes will be removed.
I’m glad you found a solution that meets your needs. Just a note that those attributes are for internal use only and thus may change or be removed at any time.
Thanks for the heads up Archetyped, many thanks for the plugin. I highly recommend it.
Is this a feature that you would implement into future versions as I believe that many users would like to have the option not to use the original (potentially very large) image for the lightbox.
For completeness, in addition to my previous post, I also changed this:
// Load image
img.src = item.get_uri();
to:
if(item._attr_default.sizes.large) {
// Load image (edited for resized image)
img.src = item.get_uri().replace(item._attr_default.sizes.original.file, item._attr_default.sizes.large.file);
} else {
// Load image
img.src = item.get_uri();
}