Ability to Hide Blocks in WordPress 6.9

WordPress 6.9 now includes a built-in feature to hide blocks, making it easy to tuck content away without deleting it. You can now hide blocks: select a blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience., click the ellipsis, and choose “Hide”. Hidden blocks are visually removed from the editor, and fully omitted from the published markup. Scripts and styles for hidden blocks are also omitted from the rendered page by default (see WordPress 6.9 Frontend Performance Field Guide for more details).

To unhide a block, open the List View, identify hidden blocks via the “Hidden” icon next to them, open the ellipsis menu again, and choose “Show”. You can also toggle Hide/Show from the keyboard: use Ctrl + Shift + H on Windows or Linux, + Shift + H on macOS.

How to disable the hide option

Because it is implemented as a standard Block APIAPI An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. support flag, opting into or out of this capabilitycapability capability is permission to perform one or more types of task. Checking if a user has a capability is performed by the current_user_can function. Each user of a WordPress site might have some permissions but not others, depending on their role. For example, users who have the Author role usually have permission to edit their own posts (the “edit_posts” capability), but not permission to edit other users’ posts (the “edit_others_posts” capability). aligns with the rest of the block supports.

The support is enabled by default for every block type except for a short list of coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. blocks. To disable the support selectively, hook into the block_type_metadata() filter, adjust the metadata, and update the supports.visibility flag:

function disable_block_visibility_support( $metadata ) {
	// Disable visibility support for the core/group block.
	if ( isset( $metadata['name'] ) && 'core/group' === $metadata['name'] ) {
		$metadata['supports']['visibility'] = false;
	}
	return $metadata;
}
add_filter( 'block_type_metadata', 'disable_block_visibility_support' );

For additional implementation details and history, see Gutenberg PR #71203.


Props to @joen for co-authoring the note.
Props to @westonruter, @ramonopoly for review.

#6-9, #dev-notes, #dev-notes-6-9