wpengine / wpengine/wp-graphql-content-blocks

`attributes.align` always`null` on paragraph/heading blocks since WordPress 7.x

Open
#457 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
149
Forks
16
PR merge metrics
No merged PRs in 30d

Description

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).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how CoreParagraph and CoreHeading attributes are mapped into the GraphQL schema, focusing on the WordPress 7.x distinction between the editor's textAlign value and the exposed align field. Reproduce the query with center and right alignment, then verify that align returns those values while cssClassName remains available as before.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, php, wordpress
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.