Add Lightbox To WordPress Native Gallery

Is there a way to check if a gallery is linked to an attachment page or to an image file via jQuery or WP filter?

I’m trying to add a lightbox to gallery image that is linked to image file. But I can’t do it since there’s no way to tell the difference between image linked to attachment page or image file in the html codes generated by WordPress.

Related posts

1 comment

  1. By default there is a difference in the HTML output for images inserted alone or via [gallery].

    A direct image link will output an <a href=""> to an actual image mime type, like:
    <a href="some-image.jpg">

    An attachment <a href=""> outputs an attachment URI like:
    <a href="some-link?attachment_id=126" or ../attachment/2013/

    As for a filter I don’t think there is a way unless you parse the_content for the above matches.

Comments are closed.