4

I'm working on a Wordpress site, where all images inside posts are linking to the corresponding attachment pages. I want to use a lightbox but obviously this would require changing all the links back to the media files directly (e.g. xyz.jpg).

The site has a significant number of posts and images so it would be impossible to do this manually.

Does anyone know of solution that would simply replace - in bulk - all of the image links to link to the media file, instead of the attachment page?

0

1 Answer 1

2

I found a nice snippet at this site for your functions.php that does the trick:

 add_shortcode( 'gallery', 'file_gallery_shortcode' ); 

 function file_gallery_shortcode( $atts ) {
      $atts['link'] = 'file';
      return gallery_shortcode( $atts );
 }

I'd actually been looking unsuccessfully for the same thing, so I'm glad you asked.

2
  • Thank you, nice trick to override the gallery shortcode. But this would only work for images embedded in a gallery, though. I would need it to happen for all images in posts.
    – Pim
    Commented Apr 17, 2014 at 20:26
  • Did you ever find a solution for this? I'm looking for it too!
    – Webreaper
    Commented Sep 20, 2018 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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