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.

How was it for you? Let me know on BlueSky or Mastodon

(Please) 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.

Related Posts

27 Oct 2013

WordPress Numeric Pagination

I’ve made quite a few WordPress themes in my time, and so I thought I would write a few blog posts sharing some of the code snippets that I find myself using repeatedly.First off is some numeric pagination using native...
31 Oct 2013

WordPress – Estimated Reading Time

I have a theme coming out soon that displays the ‘estimated reading time’ for each blog post on the homepage.The theme is inspired by the new blogging service Medium – but I first saw the idea mentioned on Brian Crays...
17 Oct 2012

WordPress Social Network Aggregation

I really like the idea of a Tumblog – and even have one on Tumblr.com – but I don’t promote it anywhere. Conceptually it’s great – but I don’t like not having control over my content.What I would really like...
10 Jan 2017

WordPress Jetpack Admin Backup: For When There are Problems

I’m a big fan of the Jetpack WordPress plugin. I support it in all of my WordPress themes, and have even contributed to its development. However it’s not perfect, and I have recently had some issues with the new React...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
06 Apr 2017

Fixing Typographic Widows in WordPress

Typography on websites is hard – especially if that site is powered by a CMS such as WordPress. Making the text on a site look good when the screen size, or content, can be changed means that often you have...