Discover in this tutorial how to get a list of all the registered blocks of a WordPress installation using code.
In a WordPress installation there may be multiple registered blocks, some added by the WordPress core and others by plugins (and/or themes). Therefore, it is possible that in some cases you may be interested in obtaining a list of all the blocks of a WordPress installation.
With this information you can decide if you prefer some of them not to be shown and unregister them so that they are not displayed in the editor.
Let’s take a look at it:
Steps to get all registered blocks in a WordPress site
1. Go to edit a post
First you have to go to edit an existing post or if you prefer you can create a new one. The important thing is that you are in the backend of a post.
2. Use the browser inspector console
Open the browser inspector (Cmd + Alt + I or Ctr + Alt + I, in most browsers), go to the console section and type:
wp.blocks.getBlockTypes()
When you hit enter you will get an array with all the registered blocks. Something like this:
In this screenshot only the first 39 are shown, but the list continued up to 111.
And that’s because in this installation only native blocks and Genesis Blocks are registered.
By the way, if you want to have at hand the list of native blocks, here you have it:
- core/archives
- core/audio
- core/button
- core/buttons
- core/calendar
- core/categories
- core/classic
- core/code
- core/column
- core/columns
- core/cover
- core/file
- core/latest-comments
- core/latest-posts
- core/legacy-widget
- core/gallery
- core/group
- core/heading
- core/html
- core/image
- core/list
- core/media-text
- core/more
- core/navigation
- core/navigation-link
- core/nextpage
- core/paragraph
- core/preformatted
- core/pullquote
- core/quote
- core/rss
- core/search
- core/separator
- core/shortcode
- core/social-link
- core/social-links
- core/spacer
- core/subhead
- core/table
- core/tag-cloud
- core/text-columns
- core/verse
- core/video
- core/widget-area
And those of Genesis Blocks:
- genesis-blocks/gb-accordion
- genesis-blocks/gb-columns
- genesis-blocks/gb-column
- genesis-blocks/gb-button
- genesis-blocks/gb-cta
- genesis-blocks/gb-container
- genesis-blocks/gb-devices
- genesis-blocks/gb-drop-cap
- genesis-blocks/newsletter
- genesis-blocks/gb-layouts
- genesis-blocks/gb-notice
- genesis-blocks/gb-post-grid
- genesis-blocks/gb-pricing
- genesis-blocks/gb-pricing-table
- genesis-blocks/gb-pricing-table-price
- genesis-blocks/gb-pricing-table-features
- genesis-blocks/gb-pricing-table-title
- genesis-blocks/gb-pricing-table-subtitle
- genesis-blocks/gb-pricing-table-button
- genesis-blocks/gb-profile-box
- genesis-blocks/gb-sharing
- genesis-blocks/gb-spacer
- genesis-blocks/gb-testimonial
With this simple trick you can also get the ones from your favorite block collection plugin. 😉
Conclusions
Now you know how to get a list with all the blocks registered in a WordPress installation to decide if you need them all or not.