Skip to content

"This block contains unexpected or invalid content" in WordPress

Why the WordPress block editor says "This block contains unexpected or invalid content", what each of the four recovery buttons writes back into your saved markup, and how to find every post at risk.

The yellow banner means exactly one thing: the HTML stored in post_content for that block is not the HTML the block’s save() function produces today. Nothing is corrupted, nothing is lost, and the front end almost always still renders correctly — the editor is simply refusing to turn markup it cannot vouch for back into an editable block. The trigger is nearly always a change on the code side (a block plugin updated, a plugin deactivated, a theme filter rewriting output, a security layer stripping an attribute) rather than anything you typed. Before you click any of the four buttons the banner offers, copy the block’s markup out of the post, because three of the four rewrite post_content the moment you press Update.

What you’ll accomplish

  • Read the block grammar inside post_content and name the exact block that failed validation.
  • Choose between Attempt Block Recovery, Convert to HTML, Convert to Blocks and the diff view knowing precisely what each writes back.
  • Trace the failure to the plugin update, save-time filter or KSES rule that changed the expected output.
  • List every post that is a candidate for the same failure instead of discovering them one editorial complaint at a time.
  • Recognise the cases where recovering the post is the wrong move and reverting the code is the right one.

Prerequisites

  • WordPress 5.0 or later using the block editor. Examples target 6.x; the grammar has been stable since 5.0.
  • Shell access with WP-CLI 2.x. Confirm with wp --info, which prints the WP-CLI version and the PHP binary in use.
  • Database read access through wp db query. The SQL below uses LENGTH, REPLACE and HAVING on aliases, handled by MySQL 5.7+ and MariaDB 10.3+.
  • A browser with a JavaScript console. Part of this guide runs inside the editor’s own page context, the only place the real validator lives.
  • A fresh backup before you write anything: wp db export takes one.
  • Examples use example.com, post ID 12 and the default wp_ table prefix. Substitute your own throughout.

How it works

Gutenberg does not store blocks. It stores HTML with block delimiters written as HTML comments, and it rebuilds the block objects from that HTML every single time the editor loads a post. An aligned paragraph is saved as an opening comment carrying a JSON attributes object, then the rendered HTML, then a closing comment: <!-- wp:paragraph {"align":"center"} -->, then the p tag, then <!-- /wp:paragraph -->. Blocks that render nothing of their own are self-closing, like <!-- wp:spacer {"height":"40px"} /-->. Core blocks drop the core/ namespace prefix, so a paragraph is wp:paragraph; everything else keeps it, which is why a third-party block reads <!-- wp:kadence/rowlayout {"align":"wide"} -->.

Opening a post runs a short pipeline, and the last stage is what produces the banner.

Four-stage diagram showing stored post_content parsed into blocks, re-serialized through the registered save function, and compared to decide whether a block is valid or invalid

Three details explain most real incidents.

First, the comparison is not a string equality test. Both sides are tokenized into tags, attributes and text runs first, so attribute order, insignificant whitespace and boolean attribute spelling are forgiven. Anything beyond that is a mismatch: a missing class, a dropped style attribute, an extra wrapper div, a changed tag name.

Second, block authors are supposed to declare a deprecated array — earlier shapes of the save output that the parser should still accept and migrate. When a plugin ships a new save() without a matching deprecation, every post that used the old shape goes invalid on the next load. That is the single most common cause, and it is a code bug in the plugin, not a bug in your content. The related failure after a WordPress release is covered in Gutenberg blocks broken after a core update.

Third, there are two different banners and they need different fixes. “This block contains unexpected or invalid content” means the block type is registered and its output does not match. “Your site doesn’t include support for the … block” means the block type is not registered at all — usually the plugin is deactivated, deleted, or the content was pasted in from another site. Recovery buttons cannot help with the second one; only reinstating the plugin can.

One misconception is worth clearing up: filters on the_content run on the front end and cannot cause this banner, because the editor never calls them — it reads content.raw from the REST API. What does cause it is anything rewriting content on the way in: content_save_pre, wp_insert_post_data, rest_pre_insert_post, and wp_kses_post() applied to users lacking the unfiltered_html capability.

Step-by-step

  1. Copy the markup out before you touch a single button. Every recovery option is a write, and the original is the only thing that lets you compare afterwards.

    wp post get 12 --field=post_content > /tmp/before.html
    grep -c 'wp:' /tmp/before.html

    The grep prints a count of delimiter lines; anything above zero confirms you captured block content and not a classic-editor blob. Keep /tmp/before.html until the incident is closed.

  2. Get the actual validation error out of the browser. WordPress ships minified editor scripts in production, and the minified build silences the validator’s log. Turn on the development build first:

    wp config set SCRIPT_DEBUG true --raw

    Expected: Success: Updated the constant 'SCRIPT_DEBUG' in the 'wp-config.php' file with the value true. Reload the editor and open the console. You now get a “Block validation failed” group naming the block, with the expected token and the actual token side by side. That pair is the diagnosis: it names the attribute or tag that changed.

  3. List every invalid block on the open post, including nested ones. Top-level getBlocks() misses blocks nested inside a group or columns, so flatten first. Paste into the console on the editor screen:

    const flat = ( bs ) => bs.flatMap( ( b ) => [ b, ...flat( b.innerBlocks ) ] );
    flat( wp.data.select( 'core/block-editor' ).getBlocks() )
      .filter( ( b ) => ! b.isValid )
      .map( ( b ) => b.name );

    Expected on a healthy post: an empty array. On a broken one you get something like ['kadence/rowlayout', 'kadence/column'] — the parent and its children both fail, but only the parent’s cause matters.

  4. Pick a recovery option deliberately. The four buttons are not interchangeable, and the banner presents them as if they were.

    Decision diagram comparing the four block recovery buttons, what each one writes back into post_content, and when to use it

    Resolve opens the diff view and changes nothing until you choose, so it is always the safe first click. Attempt Block Recovery re-runs save() on the parsed attributes and replaces the stored markup with today’s output — text and attributes survive, hand-written HTML tweaks do not. Convert to HTML wraps the existing markup in one core/html block, preserving the rendering but ending the content’s life as an editable block. Convert to Blocks throws the markup back at the parser to be re-guessed as core blocks, discarding custom attributes and delimiters. Nothing reaches the database until you save the post.

  5. Find the code change that caused it. Compare the block names actually present in your content against the block types the site registers today.

    wp eval 'foreach ( WP_Block_Type_Registry::get_instance()->get_all_registered() as $n => $t ) { echo $n . PHP_EOL; }' | sort > /tmp/registered.txt
    wc -l /tmp/registered.txt

    Expected: a few hundred lines on a typical site, core/paragraph among them. Now inventory what your posts contain:

    wp eval '
    function sh_walk( $blocks, &$out ) {
      foreach ( $blocks as $b ) {
        if ( ! empty( $b["blockName"] ) ) { $out[ $b["blockName"] ] = ( $out[ $b["blockName"] ] ?? 0 ) + 1; }
        if ( ! empty( $b["innerBlocks"] ) ) { sh_walk( $b["innerBlocks"], $out ); }
      }
    }
    $out = [];
    $ids = get_posts( [ "post_type" => "any", "post_status" => "any", "posts_per_page" => -1, "fields" => "ids" ] );
    foreach ( $ids as $id ) { sh_walk( parse_blocks( get_post_field( "post_content", $id ) ), $out ); }
    ksort( $out );
    foreach ( $out as $name => $count ) { echo $name . PHP_EOL; }
    ' > /tmp/incontent.txt
    comm -23 /tmp/incontent.txt /tmp/registered.txt

    Anything comm prints is a block name present in your content but not registered server-side. Two caveats keep this honest: blocks registered only in JavaScript never reach the PHP registry, so expect false positives, and this finds missing blocks rather than changed ones. Cross-check the survivors against recently updated plugins:

    wp plugin list --status=active --fields=name,version,update_version --format=table
  6. Rule out save-time filtering, which is the cause people always miss. If a block is fine for an administrator and invalid for an editor, KSES is stripping attributes on save.

    wp config get DISALLOW_UNFILTERED_HTML
    wp eval 'var_dump( current_user_can( "unfiltered_html" ) );' --user=2

    Expected on an unrestricted single-site administrator: bool(true). A bool(false), or a DISALLOW_UNFILTERED_HTML constant set to true, means wp_kses_post() runs over the content on the way into the database and quietly drops style attributes, data- attributes and unfamiliar tags — the exact ingredients of a block’s saved markup. Then grep for plugins rewriting content on save:

    grep -rn 'content_save_pre\|wp_insert_post_data\|rest_pre_insert_post' wp-content/plugins wp-content/mu-plugins | grep -v '/vendor/'

    Any hit is a candidate. Deactivate it, edit and re-save a test post, and see whether the markup survives intact.

  7. Bulk-detect candidate posts in SQL. Block validation runs in JavaScript, in the browser, against the JS block registry — PHP genuinely does not know whether a block is valid, so no WP-CLI command can give you a verdict. What SQL can give you is a candidate list: posts whose delimiters do not balance.

    wp db query "
    SELECT ID, post_type,
      (LENGTH(post_content)-LENGTH(REPLACE(post_content,'<!-- wp:','')))/8  AS opens,
      (LENGTH(post_content)-LENGTH(REPLACE(post_content,'<!-- /wp:','')))/9 AS closes,
      (LENGTH(post_content)-LENGTH(REPLACE(post_content,' /-->','')))/5     AS voids
    FROM wp_posts
    WHERE post_status IN ('publish','draft','pending','private','future')
      AND post_content LIKE '%<!-- wp:%'
    HAVING opens - voids <> closes
    ORDER BY ID;
    "

    Expected on a clean site: Empty set. Every row returned is a post with an orphaned opening delimiter — the classic signature of markup that was truncated, minified, or hand-edited. To sweep for one specific vendor namespace instead:

    wp db query "SELECT ID, post_type, LEFT(post_title, 50) AS title FROM wp_posts WHERE post_status <> 'inherit' AND post_content LIKE '%<!-- wp:kadence/%' ORDER BY ID;"
  8. Confirm the candidates with the real validator. Take the IDs from step 7 and run them through the actual block parser, from the console of an open editor tab where every block type is registered.

    const ids = [ 12, 34, 56 ];
    const flat = ( bs ) => bs.flatMap( ( b ) => [ b, ...flat( b.innerBlocks ) ] );
    for ( const id of ids ) {
      const post = await wp.apiFetch( { path: `/wp/v2/posts/${ id }?context=edit` } );
      const bad = flat( wp.blocks.parse( post.content.raw ) ).filter( ( b ) => ! b.isValid );
      if ( bad.length ) { console.log( id, bad.map( ( b ) => b.name ) ); }
    }

    Each logged line is a confirmed failure with the offending block names. Nothing is written; this is read-only.

  9. Fix the source, then let the posts heal. If a plugin update caused it, pin the previous version on staging first and confirm the banner disappears without touching any post:

    wp plugin install kadence-blocks --version=3.2.19 --force
    wp plugin get kadence-blocks --field=version

    Expected: Success: Plugin updated. followed by 3.2.19. When the code matches what the posts were saved against, the banner is gone and no content was rewritten. If the vendor ships a corrected release with the missing deprecation, update to it and the posts migrate silently the next time each one is opened and saved.

Validate it works

Reload the editor on the worst affected post. The banner should be gone and the console check from step 3 should return an empty array. Then confirm you did not change the stored markup while proving it:

wp post get 12 --field=post_content > /tmp/after.html
diff /tmp/before.html /tmp/after.html

No output means the content is byte-identical to step 1 — the fix was in the code, not in the post, which is the outcome you want. If you did use a recovery button, diff shows exactly what changed, line by line, before you publish.

Re-run the SQL from step 7; it should print Empty set. Re-run the console sweep from step 8 over the full candidate list; it should log nothing. Check the front end of one affected URL before and after: the rendered page should be identical, because the stored HTML was already correct. Then turn the development scripts back off:

wp config set SCRIPT_DEBUG false --raw

Troubleshooting

The banner offers no recovery button at all. You are looking at the other message — “Your site doesn’t include support for the … block”. The block type is not registered, so there is nothing to validate against and nothing to recover to. Reactivate or reinstall the plugin that provides the namespace you found in step 5. If the plugin is truly gone, Convert to HTML is the only lossless choice.

Recovery succeeds, then the banner returns on the next load. The block’s save() output is not deterministic. Blocks that generate an ID at save time, embed a timestamp, or emit classes in an unstable order fail validation on every load no matter how often you recover them. Confirm by recovering, saving, reloading and diffing post_content twice: if the markup changes each time, only a code fix helps. Report it upstream with both tokens from the step 2 console output.

It only breaks for certain authors. This is KSES, and step 6 shows it. Contributors, Authors and Editors do not hold unfiltered_html on multisite, and no role holds it when DISALLOW_UNFILTERED_HTML is defined. Their saves get sanitized, and blocks relying on inline styles or custom attributes go invalid. Either stop those blocks depending on stripped attributes, or grant the capability deliberately, knowing what it permits.

Every post went invalid at once, site-wide. Look for something removing HTML comments in bulk. An HTML minifier applied at save time, a migration script that ran content through a sanitizer, or a search-and-replace touching delimiter strings destroys the block grammar permanently — the content is plain HTML now, and no button restores structure that is no longer in the database. Restore from backup rather than recovering post by post. Also check for a theme calling allowed_block_types_all with a list that excludes blocks already used in content.

The console prints nothing even with SCRIPT_DEBUG on. A caching layer or an asset optimizer is still serving the minified bundles. Confirm the editor is loading wp-includes/js/dist/blocks.js rather than blocks.min.js in the Network tab, purge the object cache with wp cache flush, and exclude admin screens from any optimization plugin. Related constants and what each one does are covered in WordPress debug modes explained.

When this is the wrong approach

If hundreds of posts are affected and the plugin is still maintained, mass-converting content is the expensive mistake. The correct fix is one deprecated entry in the plugin, shipped once, after which every post migrates on its own. Opening 400 posts to click a button turns a vendor bug into permanent damage to your content structure.

Convert to HTML is a fine tactical move on one post before a deadline and a poor strategy across a site. Content frozen into core/html blocks stops responding to theme changes, global styles and future block updates, and the next redesign has to unpick it by hand.

If the front end renders correctly and nobody is editing that post today, doing nothing is legitimate. This banner is an editor-side problem: it does not affect visitors, search engines or revenue, and it does not justify a rushed change during business hours.

The grammar, the save() contract and the deprecation mechanism are all documented in the WordPress Block Editor Handbook, and the commands used above are listed in the WP-CLI command reference.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.