Automatically Link all Images to Full Size for Lightbox
-
Hello, I’ve been searching unsuccessfully for a function to automatically link all the_content images to their Media File URL so this doesn’t have to be done manually in the interface for hundreds of existing images. Since these are images displayed via the_content I don’t have access to the markup to do so in my theme like I would with post thumbnails. Once the images are linked to their full size media file I can make them open in a lightbox.
The closest I’ve come is wrapping images in a span.
function filter_images($content){ return preg_replace('/<img (.*) \/>\s*/iU', '<span class="className"><img \1 /></span>', $content); } add_filter('the_content', 'filter_images');
Would this be the way to also link to the media file URL? I can see how I’d wrap the image in a link but not sure how I’d get the actual URL to use as the src. The image may not be an attachment to this exact post so we can’t lean on that.
Any info is appreciated!
- The topic ‘Automatically Link all Images to Full Size for Lightbox’ is closed to new replies.