Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andreawetzel/4af2d399ad6d2d2f2801ed28e381aef1 to your computer and use it in GitHub Desktop.

Select an option

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
<?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