Skip to content

Page sources drop className from the saved HTML of static core blocks #196

Closed

Description

@vinnysgreen

Blockstudio 7.7.10, WordPress 7.1.4, PHP 8.3

A file-backed page (pages/<name>/index.php) that sets a custom class on a core block saves the class in the block's comment attributes but not in its HTML. Static blocks render from their saved HTML, so the class never reaches the front end. The block editor also flags these blocks as invalid, because the saved HTML doesn't match the attributes.

Reproduce

echo ( new Blockstudio\Html_Parser() )->parse( <<<'HTML'
<p class="a">Hello</p>
<block name="core/paragraph" className="b">Hi</block>
<block name="core/group" className="ledger-x" layout='{"type":"constrained"}'><h2 class="t">Title</h2></block>
<block name="core/buttons"><block name="core/button" url="/join/" className="is-style-outline">Join</block></block>
HTML );

Output (trimmed):

<!-- wp:paragraph {"class":"a"} --><p>Hello</p><!-- /wp:paragraph -->
<!-- wp:paragraph {"className":"b"} --><p>Hi</p><!-- /wp:paragraph -->
<!-- wp:group {"className":"ledger-x","layout":{"type":"constrained"}} --><div class="wp-block-group"><!-- wp:heading {"class":"wp-block-heading t","level":2} --><h2 class="wp-block-heading">Title</h2>…
<!-- wp:button {"url":"/join/","className":"is-style-outline"} --><div class="wp-block-button">…

do_blocks() on that output renders <p class="wp-block-paragraph">Hi</p>, <div class="wp-block-group …"> and <h2 class="wp-block-heading">, all without the custom classes.

Expected

  • className is added to the block's wrapper element in the saved HTML, as the editor's save() does: <p class="b">, <div class="wp-block-group ledger-x">, <div class="wp-block-button is-style-outline">.
  • A class on a mapped HTML element (<p class="a">, <h2 class="t">) becomes className and stays in the HTML, as the docs already describe for lists ("A class on a list or an item becomes its className").

Also seen

Serialized block markup (<!-- wp:… -->) in a page source is parsed as plain HTML. Its comment attributes are dropped, a core/query turns into an empty group, and Blockstudio blocks written as comments disappear. If that is intended, the Content Sources docs could say so. A raw or serialized passthrough would let existing patterns move into page files unchanged.

Activity

  1. dnnsjsk commented on Nov 4, 2026

    @dnnsjsk
    Contributor

    Fixed and released in 7.7.12, included in ff1b433.

    Core block classes now survive in both the block attributes and saved HTML, including mapped elements, groups, and button styles. Sources containing serialized WordPress blocks also preserve their attributes, nested blocks, and dynamic blocks instead of being reparsed as HTML.

    For existing file-backed pages, run wp bs pages sync once after upgrading to regenerate the saved markup. Unchanged sources are reparsed once for this parser upgrade; locked pages and sync: false remain protected. No automatic request-time sync was added.

    Regression coverage includes frontend rendering, Gutenberg block validation and saving, serialized-source preservation, and the repair-once migration. Full CI and distribution checks passed. Thanks for the detailed reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions