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?

1 Answer
1

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.

Leave a Reply

Your email address will not be published. Required fields are marked *