Remove admin menu items

Our GenerateBlocks admin menu item has a handful of sub-menu items.

To remove the Location Templates or Global Styles menu items, we can do the below.

add_filter( 'register_post_type_args', function( $args, $post_type ) {
	// Local Templates.
	if ( 'gblocks_templates' === $post_type ) {
		$args['show_in_menu'] = false;
	}

	// Global Styles.
	if ( 'gblocks_global_style' === $post_type ) {
		$args['show_in_menu'] = false;
	}

	return $args;
}, 10, 2 );

For the Asset Library, we can do this:

add_action( 'admin_menu', function() {
	remove_submenu_page( 'generateblocks', 'generateblocks-asset-library' );
}, 20 );
2 Likes

Just a heads up that the links are still accessible from the dashboard header with this code snippet.