# Readability Score Panel in the Block Editor

> Adds a "Readability" panel to the block editor sidebar with the word count, average sentence length, number of very long sentences and a Flesch reading ease score that updates as you write.

- Type: PHP
- Runs: Admin only
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: readability, block-editor, writing
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-readability-panel/

## Code

```php
add_action( 'enqueue_block_editor_assets', function () {
    wp_register_script( 'wpide-readability', '', array( 'wp-plugins', 'wp-editor', 'wp-element', 'wp-data' ), null, true );
    wp_enqueue_script( 'wpide-readability' );
    wp_add_inline_script( 'wpide-readability', <<<'JS'
(function (wp) {
    var el = wp.element.createElement;
    var Panel = (wp.editor && wp.editor.PluginDocumentSettingPanel) || (wp.editPost && wp.editPost.PluginDocumentSettingPanel);
    if (!Panel) { return; }
    function syllables(word) {
        word = word.toLowerCase().replace(/[^a-z]/g, '');
        if (word.length <= 3) { return 1; }
        word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '').replace(/^y/, '');
        var m = word.match(/[aeiouy]{1,2}/g);
        return m ? m.length : 1;
    }
    function Readability() {
        var html = wp.data.useSelect(function (select) { return select('core/editor').getEditedPostContent(); }, []);
        var text = new DOMParser().parseFromString(html || '', 'text/html').body.textContent || '';
        var sentences = text.split(/[.!?]+\s/).map(function (s) { return s.trim(); }).filter(Boolean);
        var words = text.split(/\s+/).filter(function (w) { return /[a-z0-9]/i.test(w); });
        if (words.length < 30) { return el(Panel, { name: 'wpide-readability', title: 'Readability' }, el('p', null, 'Write a little more to see a score.')); }
        var syl = words.reduce(function (sum, w) { return sum + syllables(w); }, 0);
        var avg = words.length / Math.max(1, sentences.length);
        var flesch = Math.round(206.835 - 1.015 * avg - 84.6 * (syl / words.length));
        var long = sentences.filter(function (s) { return s.split(/\s+/).length > 25; }).length;
        var label = flesch >= 60 ? 'easy to read' : (flesch >= 40 ? 'fairly difficult' : 'difficult');
        return el(Panel, { name: 'wpide-readability', title: 'Readability' },
            el('p', null, 'Words: ' + words.length),
            el('p', null, 'Average sentence: ' + avg.toFixed(1) + ' words'),
            el('p', { style: { color: long ? '#b32d2e' : 'inherit' } }, 'Sentences over 25 words: ' + long),
            el('p', null, 'Flesch reading ease: ' + flesch + ' (' + label + ')'));
    }
    wp.plugins.registerPlugin('wpide-readability', { render: Readability });
})(window.wp);
JS
    );
} );
```

## Notes

The Flesch score is designed for English text; for other languages focus on sentence length.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Readability Score Panel 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/
