Pro Plugin Sale! Save 25% on all pro plugins w/ code: SEASONS
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! ;)

Jeff Starr
About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
WP Themes In Depth: Build and sell awesome WordPress themes.
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 »
Wizard’s SQL for WordPress: Over 300+ recipes! Check the Demo »
Thoughts
First snow of the year :)
BF Sale! Save 40% on all Pro WordPress plugins and books w/ code FRIDAY23
Sincerely trying to engage more on social media. I love the people not the platforms.
All free and pro WordPress plugins updated and ready for WP version 6.4!
Fall season almost here :)
My greatest skill on social media is the ability to simply ignore 98% and keep scrolling without interacting.
Enjoying this summer, getting some great positive energy. Refreshing and inspiring.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.