Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

Fix Gutenberg Errors

I’ve been exploring WordPress new Gutenberg functionality, and unfortunately keep encountering various weird errors. So to keep things organized and hopefully help others on the same path, I’m going to update this post with any Gutenberg errors for which I am able to find a solution. This includes any PHP errors, warnings, notices, as well as any JavaScript and/or debug/console errors.

To save time, I sometimes abbreviate Gutenberg as a numeronym: G7G or g7g.

PHP Fatal error: Uncaught Error: Call to undefined function register_block_type()

First up, the following error:

[26-Mar-2018 22:34:31 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function register_block_type() in /.../wp-content/plugins/whatever.php:111

From what I could find about this surprising error, it’s a known bug that will be fixed in a future update of Gutenberg. For those who want to resolve the issue now, here is a workaround..

The error above is related to calling the following tag directly:

register_block_type('g7g-blocks/block-06', array('render_callback' => 'g7g_render_block_latest_post'));

So look for any instances of code where register_block_type() is used, and replace with this:

function g7g_load_blocks() {
	
	register_block_type('g7g-blocks/block-06', array('render_callback' => 'g7g_render_block_latest_post'));
	
}
add_action('init', 'g7g_load_blocks');

Basically the idea here is to call register_block_type() only via the init hook, instead of just calling directly in the plugin source.

Surely, there are more errors (and solutions) to come! ;)

About the Author
Jeff Starr = Designer. Developer. Producer. Writer. Editor. Etc.
GA Pro: Add Google Analytics to WordPress like a pro.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
SAC Pro: Unlimited chats.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.