Testing custom themes / plugins under Gutenberg

You don’t need the nightly build unless you’re looking for deeper core compatibility issues. For strict Gutenberg compatibility, the plugin itself should be sufficient as long as you keep it updated. You can do the nightlies on a fresh install if you wish, but it’s unnecessary overkill IMO. I would (and do) unit testing with … Read more

WordPress Gutenberg get page template value when post updated?

So I found a solution. There are 4 hooks that can be used to accomplish this depending on the exact needs. The hooks are from wp-includes/meta.php in functions update_metadata() and add_metadata(). Hooks: update_postmeta updated_postmeta add_post_meta added_post_meta These are called at different states and from the names it is pretty self self explanatory. add_post_meta and update_postmeta … Read more

How to check if current admin page is Gutenberg editor? [duplicate]

In 5.0 new function was introduced (docs): WP_Screen::is_block_editor( bool $set = null ) which sets or returns whether the block editor is loading on the current screen. So you can do that check using this code: global $current_screen; $current_screen = get_current_screen(); if ( method_exists($current_screen, ‘is_block_editor’) && $current_screen->is_block_editor() ) { // DO SOMETHING } You can also add to this … Read more

Include a Gutenberg Block in a PHP file

You need to use Custom Post Type for blocks. What it does is you can register your own post template with predefined blocks in it. Which I believe is what you are looking for. Here’s example of that – function myplugin_register_book_post_type() { $args = array( ‘public’ => true, ‘label’ => ‘Books’, ‘show_in_rest’ => true, ‘template’ … Read more

How to display only the excerpt in the blog/posts page with Gutenberg?

You should use a custom page for this. For reference, we can modify the default (twentynineteen) post content block. Depending on your theme, you may need to modify single.php, or a content block included from there. In the twentynineteen theme, we can see this on line 24: get_template_part( ‘template-parts/content/content’, ‘single’ ); Following that, we can … Read more