How To Hide WordPress Core Blocks The Easy Way

How To Hide WordPress Core Blocks The Easy Way

How To Hide WordPress Core Blocks The Easy Way

Last Updated on November 11, 2023 by Mike Kipruto

Today I want to share a quick and easy tutorial on hiding some of the WordPress Core Blocks the easy way.

To achieve this, you can hook into the allowed_block_types_all filter hook. This filter allows you to modify the list of allowed block types in the block editor.

PHP
/**
 * How To Hide WordPress Core Blocks The Easy Way
 * @link https://kipmyk.co.ke/code/how-to-hide-wordpress-core-blocks-the-easy-way/
*/

add_filter( 'allowed_block_types_all', 'mk_to_allowed_block_types', 10, 2 );
 
function mk_to_allowed_block_types( $allowed_blocks, $post ) {
 
    $allowed_blocks = array(
        //pass your core allowed blocks here or any other blocks
        'core/image',
        'core/paragraph',
        'core/heading',
        'core/list'
    );
 
    return $allowed_blocks;
 
}

In this specific case, the above code restricts the available block types to a specific set of core blocks, that is, image, paragraph, and list resulting to the following in the Block Editor: