Gutenburg reusable blocks

We used to build our sites with a CPT called panels, where would add reusable content for a site. With Gutenberg we don’t need to do this anymore as it comes with reusable blocks built in.

Getting to, and managing reusable blocks seems a little hidden at the moment, so we use the script below to add this to the navigation in the WordPress admin.

<?php
function gomo_blocks_to_admin($args, $post_type){
	if ( 'wp_block' !== $post_type ) {
		return $args;
	}
    if ($post_type == 'wp_block'){      
	     $block_args = array(
			'public'				=> true,
			'show_ui'				=> true,
			'exclude_from_search'	=> true,
			'query_var'				=> true,
			'show_in_rest'			=> true,
			'publicly_queryable'	=> true,
		);
    }
	return array_merge( $args, $block_args );
}
add_filter('register_post_type_args', 'gomo_blocks_to_admin', 10, 2);

function add_reusable_blocks_admin_menu() {
    add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'add_reusable_blocks_admin_menu' );

Search

Doing this with large blocks of content means the page will not show in the search results, unless we use the Relevanssi plugin.

Search the site


Address

123 Main Street
Town
City
P05T C0D3

Tel: 01234 567 899

Mob: 01234 567 899

Email: ben@gomopress.com


Copyright 2023. Blah blah blah Company Limited