# Show the Post ID and Short Link in the Block Editor

> Adds the post ID and a copyable short link (?p=123) to the Summary panel of the block editor sidebar, which is handy for shortcodes, support tickets and quick sharing.

- Type: PHP
- Runs: Admin only
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-editor, post-id, sidebar
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/post-id-in-editor-sidebar/

## Code

```php
add_action( 'enqueue_block_editor_assets', function () {
    $screen = get_current_screen();
    if ( ! $screen || 'post' !== $screen->base ) {
        return;
    }

    wp_register_script( 'wpide-post-id-panel', false, array( 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-editor' ), '1.0', true );
    wp_enqueue_script( 'wpide-post-id-panel' );
    wp_add_inline_script( 'wpide-post-id-panel', 'var wpideHomeUrl = ' . wp_json_encode( home_url( '/' ) ) . ';' . <<<'JS'
( function ( wp ) {
    var el = wp.element.createElement;
    var Panel = ( wp.editor && wp.editor.PluginPostStatusInfo ) || ( wp.editPost && wp.editPost.PluginPostStatusInfo );
    if ( ! Panel ) { return; }

    function PostId() {
        var id = wp.data.useSelect( function ( select ) { return select( 'core/editor' ).getCurrentPostId(); }, [] );
        var copied = wp.element.useState( false );
        if ( ! id ) { return null; }
        var link = wpideHomeUrl + '?p=' + id;

        return el( Panel, null,
            el( 'div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%' } },
                el( 'span', null, 'ID ', el( 'strong', null, id ) ),
                el( wp.components.Button, {
                    variant: 'link',
                    onClick: function () {
                        if ( navigator.clipboard ) { navigator.clipboard.writeText( link ).then( function () { copied[1]( true ); } ); }
                    }
                }, copied[0] ? 'Copied!' : 'Copy short link' )
            )
        );
    }

    wp.plugins.registerPlugin( 'wpide-post-id-panel', { render: PostId } );
} )( window.wp );
JS
    );
} );
```

## Notes

The short link always redirects to the current address, even after the slug changes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show the Post ID and Short Link 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/
