Believe it or not, finding this information in the official WordPress documentation was a nightmare. I had to go through the WordPress codebase itself to find these values.
In a site I am working on, I wanted only to enable specific WordPress Gutenberg blocks. By default, my client will never use a lot of junk, like buttons and page separators that I wanted to disable.
I am using the allowed_block_types
hook to create an inclusion list where I specify what blocks I want to enable. You can also add your custom blocks to this list.
add\_filter( 'allowed\_block\_types', 'theme\_allowed\_block\_types', 10, 2 );
/\*\*
\* Set allowed block types on pages/posts/CPTs
\*/
function theme\_allowed\_block\_types( $allowed\_blocks, $post ) {
if ( ! ( $post instanceof WP\_Block\_Editor\_Context ) ) {
return $allowed\_blocks;
}
$allowed\_blocks = array(
'core/freeform',
'core/video',
'core/heading',
'core/image',
'core/gallery',
'core/embed',
'core/table',
'core/list',
'core/paragraph',
'core/pullquote',
'core/html'
);
return $allowed\_blocks;
}
A fair warning. If you’re not using WordPress 5.8 or above, the above might cause issues for you.
Here is a list of core Gutenberg block types that can be specified:
- core/paragraph
- core/image
- core/heading
- core/gallery
- core/list
- core/quote
- core/shortcode
- core/archives
- core/audio
- core/button
- core/buttons
- core/calendar
- core/categories
- core/code
- core/columns
- core/column
- core/cover
- core/embed
- core/file
- core/group
- core/freeform
- core/html
- core/media-text
- core/latest-comments
- core/latest-posts
- core/missing
- core/more
- core/nextpage
- core/preformatted
- core/pullquote
- core/rss
- core/search
- core/separator
- core/block
- core/social-links
- core/social-link
- core/spacer
- core/subhead
- core/table
- core/tag-cloud
- core/text-columns
- core/verse
- core/video