Skip to content

Bug: PhotoSwipe script wraps already linked images, breaking original links #187

@saasan

Description

@saasan

Description

I found a bug where the PhotoSwipe script (_includes/extensions/photo-swipe.html) wraps all <img> elements (except those with emoji class) in a new <a class="photo-swipe"> element, including images that are already inside a link. This causes the original link functionality to be lost.

Current Behavior

When an image is already wrapped in a link like this:

<a href="https://example.com">
  <img src="image.jpg">
</a>

The script wraps it again, resulting in:

<a href="https://example.com">
  <a class="photo-swipe" href="image.jpg" ...>
    <img src="image.jpg">
  </a>
</a>

The original link to https://example.com becomes inaccessible.

Expected Behavior

Images that are already inside <a> tags should be skipped by the script to preserve their original link functionality.

Steps to Reproduce

  1. Create a post with a linked image: <a href="https://example.com"><img src="image.jpg"></a>
  2. Load the page with PhotoSwipe enabled
  3. Click the image
  4. PhotoSwipe opens instead of following the original link

Proposed Solution

I believe this can be fixed by adding a check to skip images whose parent element is already an <a> tag. I'd be happy to submit a pull request with this fix if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions