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.
How was it for you? Let me know on BlueSky or Mastodon
Link to this page
Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.