Created
June 17, 2026 14:57
-
-
Save andreawetzel/4af2d399ad6d2d2f2801ed28e381aef1 to your computer and use it in GitHub Desktop.
WordPress Filter to add default margin and padding controls to the core Heading block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Adds default margin and padding controls to the core Heading block. | |
| * | |
| * This filters the block registration arguments for `core/heading` and | |
| * enables the `__experimentalDefaultControls` settings for spacing, | |
| * specifically turning on default margin and padding controls. | |
| * | |
| * @param array $args The block type registration arguments. | |
| * @param string $block_type The block type being registered. | |
| * | |
| * @return array Modified block registration arguments. | |
| */ | |
| function my_theme_heading_default_controls( $args, $block_type ) { | |
| if ( $block_type === 'core/heading' ) { | |
| $args['supports']['spacing']['__experimentalDefaultControls'] = [ | |
| 'margin' => true, | |
| 'padding' => true, | |
| ]; | |
| } | |
| return $args; | |
| } | |
| add_filter( 'register_block_type_args', 'my_theme_heading_default_controls', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment