WordPress get_post_gallery() Gutenberg Polyfill

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.

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

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.

WordPress News

The latest WordPress updates from the WPBriefs Podcast.

Related Posts

13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...
31 May 2007

WordPress tips and tricks – functions.php

Functions.php is a little known wordpress template file. Not many themes take advantage of it but , used properly, it can be incredibly powerful. The file can be used as a way to add your own functions to wordpress themes...
05 Jul 2016

Dogfooding a New WordPress Design

Eating your own dog food, also called dogfooding, is a slang term used to reference a scenario in which a company uses its own product to test and promote the product.Wikipedia – DogfoodingThis is another thing on the long list...
20 Jul 2016

Empathy in Web Design

I wasn’t able to make WordCamp Europe this year, but they’ve been really quick at getting all of the talks online, and so I have been watching some of them – and this one stood out.Morten Rand-Hendriksen is an experienced...