Learn how to remove core WordPress blocks and improve your theme’s design and functionality. Our guide provides detailed steps for unregistering unnecessary blocks.
While I try to support all major components in the theme builder, sometimes it makes sense to remove core WordPress block/components. Mainly because I’ve developed a custom tool that seems to be my main stop when dealing with design and performance requirements. Most of my themes include a ‘Content and Images’ block, similar to ‘Media and Text’ but with the theme’s grid layout.
Sometimes I save a “Call” book and make my own call. Use the php file in the theme that ensures the search block matches the design and functionality of the search function used elsewhere in the theme.
Table of Contents
- Why Remove Core Blocks
- Enqueue Block Editor Assets
- Unregister Block Type
- Unregister Blocks Everywhere
Why Remove Core WordPress Blocks
If you need more control over your theme’s design and functionality, removing important components can be helpful. Blocking products can provide a better experience and better match your theme’s unique features and aesthetics. For example, you can use the enqueue_block_editor_assets hook to load the text and style into the
editor.
- Consistency: Custom blocks ensure consistent design across your site.
- Functionality: Tailored blocks can offer additional or specific functionality that core blocks lack.
- Performance: Removing unused core blocks can reduce bloat and improve performance.
Enqueue Block Editor Assets
My themes usually have an author. I create the js file that I use in block mode and save the block type. I also want custom fonts used internally so I can use them in the editing process as well. Here’s how to control author sources:
/**
* Gutenberg scripts and styles
*
*/
function be_gutenberg_scripts() {
wp_enqueue_style( 'theme-fonts', be_theme_fonts_url() );
wp_enqueue_script( 'theme-editor', get_template_directory_uri() . '/assets/js/editor.js', array( 'wp-blocks', 'wp-dom' ), filemtime( get_template_directory() . '/assets/js/editor.js' ), true );
}
add_action( 'enqueue_block_editor_assets', 'be_gutenberg_scripts' );
/**
* Theme Fonts URL
*
*/
function be_theme_fonts_url() {
return 'https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap';
}
This code uploads your custom fonts and typefaces to the author block so you can personalize and manage the environment.
Unregister Block Type
Now that you have created an editor. You can place the js file into the
block editor and use wp. Stop UNRegisterBlockType To unregister the block type. Here is an example of how to register basic components:
jsCopy codewp.domReady( () => {
wp.blocks.unregisterBlockType( 'core/media-text' );
wp.blocks.unregisterBlockType( 'core/search' );
} );
This JavaScript component needs to be added to your editor. file. It ensures that the specified restrictions are not written and cannot be found by editing the editor.
Unregister Blocks Everywhere
The above code only saves the “Edit Post” block. If you are trying to remove restrictions on the Widgets screen, Full Site Editor, or Templates, you will need to change the settings.
You can extend the above process by ensuring that the unsubscribe process applies to all relevant areas. For a complete guide on how to unblock WordPress from any domain, check out this keyword:
Further Reading
For a comprehensive guide on unregistering WordPress blocks from all areas, refer to wordpress: How to Unregister WordPress Blocks (from everywhere!).
How to Unblock WordPress (Anywhere!). For more information, check out this article by Jason Lemahieu: Register a WordPress blog (fromplaces!) By following these steps, you can effectively manage the content available in your WordPress theme and ensure that your products deliver an efficient and effective experience. for your users.