Skip to content

attributes.align alwaysnull on paragraph/heading blocks since WordPress 7.x #457

Description

@marco910

Describe the bug

Since WordPress 7.x (tested with WP 7.x + Gutenberg), the attributes.align field on CoreParagraph and CoreHeading blocks always returns null via GraphQL, even when a text alignment is explicitly set in the editor.

The only workaround is to query attributes.cssClassName, parse the resulting string for a has-text-align-* class, and extract the alignment value manually — which is brittle and should not be necessary.

To Reproduce

  1. Create a post with a Paragraph or Heading block
  2. Set a text alignment (e.g. center or right) via the block toolbar in the editor
  3. Query the block via WPGraphQL Content Blocks:
query {
  post(id: "...", idType: DATABASE_ID) {
    editorBlocks {
      ... on CoreParagraph {
        attributes {
          align
          cssClassName
        }
      }
      ... on CoreHeading {
        attributes {
          align
          cssClassName
        }
      }
    }
  }
}

Expected behavior

attributes.align should return the text alignment value set in the editor (e.g. "center", "right"), consistent with how the block attribute is defined in block.json.

Actual behavior

attributes.align is always null.

attributes.cssClassName correctly contains the alignment class (e.g. "has-text-align-center"), which can be used as a workaround — but requires manually parsing the class string:

const align = cssClassName
  ?.split(' ')
  .find(c => c.startsWith('has-text-align-'))
  ?.replace('has-text-align-', '') ?? null;

Environment

  • WordPress version: 7.0
  • WPGraphQL version: 2.16.0
  • WPGraphQL Content Blocks version: 4.8.5

Additional context

It appears that WordPress 7.x changed how the text alignment for headings is presented in the GraphQL schema. In the editor, the value is stored in textAlign but in GraphQL it is only available in the align attribute (which is currently always null).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    🆕 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions