Ben
Ben is a lifelong Nintendo fan who likes to build websites, and make video games. He buys way too much Lego.
WordPress and Games
I’m working on a new WordPress theme designed for Gutenberg, however Gutenberg isn’t finished, and there are elements that won’t work until the plugin is merged with core.
One such issue, that I ran into this weekend, is that get_post_gallery() doesn’t work with Gutenberg gallery blocks. There’s an open Github issue (and trac ticket) about this, but that’s no help since I don’t want to wait for the final release. So I made a small polyfill that replaces the code, and have added it to Github so anyone can use it.
The bit that does the hard work is only 4 lines long, it’s a regex that checks for the gallery code and then returns the required html.
The code itself is actually quite short. A lot of the polyfill is making sure that Gutenberg is enabled, and in use on the current blog post.
I am currently using this locally, for development, and as an mu-plugin on my theme demo site so that I can test the theme with production ready content. Once 5.0 drops I can delete the script and move on. Simples.
Thanks to Gabor Javorszky for help with the regex.
Could you add support to get src of images?
Now it’s been merged in to core I can probably remove the polyfill (although I need to test to make sure it works as expected).
I think what you want to do is a separate request and I’m afraid I don’t know how to do it – at least not off the top of my head.
Thanks for the tricks. However, you said “Now it’s been merged in to core”. Where I can find the documentation about that? I definitively needs to add a custom template to my gallery block.
Looks like I might have been wrong about the fix being merged. I was referring to Gutenberg being merged. I had previously been told there was a fix that would be added before the Gutenberg merge.
I don’t know why it’s not there yet.
get_post_gallery() doesn’t work in wordpress 5.0. Any workaround?
The work around is linked in the Gist in this article.