The code snippet you provided accomplishes the desired task perfectly. It directs the user to the specified URL found in the anchor tag's href attribute, which in this case is the image URL.
Here is a demonstration of it in action:
<a rel="gallery-3" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196" title="Photo title" class="swipebox">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196" alt="image" />
</a>
You can customize the URL to be anything you want, such as linking it to Stack Overflow instead.
Check out this example with the modified link:
<a rel="gallery-3" href="https://stackoverflow.com/help/how-to-ask" title="Photo title" class="swipebox">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196" alt="image"/>
</a>
In the specific case of using swipebox, make sure the anchor tag includes the "swipebox" class for it to function correctly in the lightbox view. However, note that the image won't load if it's sourced from a different server due to the "Cross-Origin Read Blocking" error. This limitation can be observed in the console of your browser's developer tools when attempting to use an external image like in the stackoverflow example snippet...