# Warn About H1 Headings in the Block Editor

> Shows a warning in the block editor when a post contains an H1 heading block, since the post title is already the page's H1 and a second one muddles the outline.

- Type: PHP
- Runs: Admin only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: headings, gutenberg, content
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/seo-h1-warning-block-editor/

## Code

```php
add_action( 'enqueue_block_editor_assets', function () {
    wp_register_script( 'wpide-h1-warning', false, array( 'wp-data', 'wp-notices', 'wp-block-editor' ), '1.0', true );
    wp_enqueue_script( 'wpide-h1-warning' );
    wp_add_inline_script( 'wpide-h1-warning', <<<'JS'
( function ( wp ) {
    var id = 'wpide-h1-warning', last = null, timer = null;
    var hasH1 = function ( blocks ) {
        return blocks.some( function ( block ) {
            return ( block.name === 'core/heading' && block.attributes.level === 1 ) || ( block.innerBlocks && hasH1( block.innerBlocks ) );
        } );
    };
    wp.data.subscribe( function () {
        clearTimeout( timer );
        timer = setTimeout( function () {
            var editor = wp.data.select( 'core/block-editor' );
            var found = editor ? hasH1( editor.getBlocks() ) : false;
            if ( found === last ) {
                return;
            }
            last = found;
            if ( found ) {
                wp.data.dispatch( 'core/notices' ).createWarningNotice( 'This post contains an H1 heading. The title is already the H1, so use H2 for main sections.', { id: id, isDismissible: true } );
            } else {
                wp.data.dispatch( 'core/notices' ).removeNotice( id );
            }
        }, 400 );
    } );
} )( window.wp );
JS
    );
} );
```

## Notes

The warning disappears as soon as the heading is changed to H2 or removed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Warn About H1 Headings in the Block 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/
