# Limit Heading Levels in the Editor

> Shows only the heading levels you allow (for example H2 to H4) in the Heading block toolbar, so editors keep a clean document outline and never add a second H1.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: headings, accessibility, editor
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/limit-heading-levels/

## Code

```php
// Heading levels to offer.
$wpide_heading_levels = array( 2, 3, 4 );

add_filter( 'register_block_type_args', function ( $args, $block_type ) use ( $wpide_heading_levels ) {
    if ( 'core/heading' !== $block_type || ! isset( $args['attributes'] ) ) {
        return $args;
    }

    $args['attributes']['levelOptions'] = array(
        'type'    => 'array',
        'default' => array_map( 'intval', $wpide_heading_levels ),
    );

    return $args;
}, 10, 2 );
```

## Notes

Requires WordPress 6.7 or newer. Existing headings keep their level.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit Heading Levels in the Editor" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
