Adding a link to a whole block using the WordPress block editor

I have a gallery of sites on my Showcase page, and I wanted it so that clicking on that gallery would take you through to my Showcase Sites page.

Not obvious.

The gallery block only allows you to add links to the images, and then only to the attachment page or the media file. So that’s no good.

The gallery block itself is in a <figure> element, so wrapping that in an <a> tag is semantically incorrect, and the block editor throws up errors.

How about putting the gallery inside a group block and then wrapping that in an <a> tag? The group block is a <div> so wrapping that in an anchor is OK in HTML5. But using the page code editor still throws up errors.

The answer is to add one custom html block before the group block and another after it, the first containing <a href="the-url"> and the second containing </a>. Works perfectly…

Leave a Reply

Your email address will not be published.