Gallery with Popup window for Gutenberg in WordPress.

Gallery with Popup window for Gutenberg in WordPress.
Examining the list of blocks in Gutenberg in detail, I came across a gallery block that can be easily created in the editor. The gallery block is a list of images that are loaded with standard wordpress tools and with which you can then do whatever you want in the gallery.

But, as it turned out, it is convenient to only upload images to the gallery. And other aspects of working with images cause inconvenience during processing.

Gallery with Popup window for Gutenberg in WordPress

And the gallery itself for the front office displays just a list of pictures, even without the popup window, which has long been a must have on all sites. This, of course, is about the boxed version of wordpress, with the standard twentytwentytwo theme at the moment.

  Gallery with Popup window for Gutenberg in WordPress

So, the task is to bolt a popup window to this gallery with minimal processing of a list of ready images for the front office. To solve it we need a plugin that will process the list of images and load them into Fancybox library with usual js script. We will take the latest Fancybox version at the moment v4

So, here is the code for a ready-made plugin that will simply load js scripts to handle the DOM model:

The js itself looks like this:

You can see from it, that we take the figure element and replace it with the desired structure of the reference element a.

The structure before:

Gallery with Popup window for Gutenberg in WordPress

The structure after:

Gallery with Popup window for Gutenberg in WordPress

As a result, we have this popup window when you click on a gallery item.

Gallery with Popup window for Gutenberg in WordPress This option of page processing with the help of js can be used, but rarely. Since the block structure may change depending on some parameters of the gallery when editing the record. And for each such change you will need to modify the code handler.

And of course it will be much easier if you just download a well-tested plugin Classic Editor

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Leave a comment

Your email address will not be published.