Skip to content

Fix: Respect hidden attribute in Shortcode block render - #78720

Closed
riyak145 wants to merge 1 commit into
WordPress:trunkfrom
riyak145:fix/shortcode-block-visibility-support
Closed

riyak145 wants to merge 1 commit into
WordPress:trunkfrom
riyak145:fix/shortcode-block-visibility-support

Conversation

@riyak145

Copy link
Copy Markdown

What?

Closes #78701

The Shortcode block render callback does not check the hidden
attribute, causing previously hidden shortcode blocks to remain
visible on the front end even in incognito mode.

Why?

PR #76138 disabled visibility support for the Shortcode block.
However, users who had previously hidden shortcode blocks still
have {"hidden":true} saved in their database from before that
change. The render callback was not checking this attribute,
causing those blocks to render on the front end even when
marked as hidden.

How?

Added a check for the hidden attribute in the render callback
in index.php. If the block is hidden, the function returns an
empty string instead of rendering the shortcode content.

function render_block_core_shortcode( $attributes, $content ) {
    if ( ! empty( $attributes['hidden'] ) ) {
        return '';
    }
    return wpautop( $content );
}

Testing Instructions

  1. Open a post or page
  2. Add a Shortcode block
  3. Switch to Code Editor (3 dots → Code Editor)
  4. Manually add {"hidden":true} to block markup:
    <!-- wp:shortcode {"hidden":true} -->[your_shortcode]<!-- /wp:shortcode -->
  5. Publish the page
  6. Visit the page in incognito mode

Before fix: Shortcode renders visibly on front end ✗

After fix: Nothing renders — block correctly hidden

The Shortcode block render callback does not check the hidden
attribute, causing previously hidden shortcode blocks to remain
visible on the front end after PR WordPress#76138 disabled visibility support.

Changes:
- Add hidden attribute check in index.php to prevent rendering
  hidden shortcode blocks on the front end

Fixes WordPress#78701
See WordPress#76138
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 27, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @riyak145, @krysek76.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: riyak145, krysek76.


To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 27, 2026
@github-actions

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @riyak145! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riyak145 Thanks for working on this! However, this issue also occurs outside of shortcode blocks. To explore a more ideal solution, let me close this PR for now.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Shortcode Affects the Shortcode Block labels May 28, 2026
@t-hamano t-hamano closed this May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Shortcode Affects the Shortcode Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hidden (Ctrl + Shift + H) shortcode block shows up in browser in incognito mode

2 participants