Skip to content

Custom CSS: Prevent duplicate custom css styles#75892

Merged
ramonjd merged 1 commit intotrunkfrom
fix/duplicate-custom-css-for-block-instance
Feb 26, 2026
Merged

Custom CSS: Prevent duplicate custom css styles#75892
ramonjd merged 1 commit intotrunkfrom
fix/duplicate-custom-css-for-block-instance

Conversation

@aaronrobertshaw
Copy link
Copy Markdown
Contributor

@aaronrobertshaw aaronrobertshaw commented Feb 25, 2026

What?

Removes core WordPress custom CSS block support filters and action before registering Gutenberg's replacements.

Why?

PR #75799 introduced Gutenberg-prefixed versions of the custom CSS block support functions (gutenberg_render_custom_css_support_styles, gutenberg_render_custom_css_class_name, gutenberg_enqueue_block_custom_css), but did not remove the corresponding core WordPress hooks (wp_render_custom_css_support_styles, wp_render_custom_css_class_name, wp_enqueue_block_custom_css). This results in both the core and Gutenberg versions running, producing duplicate custom CSS styles on the frontend.

How?

Before registering the Gutenberg filters and action, remove the core equivalents using remove_filter / remove_action, guarded by function_exists() checks for backward compatibility with older WordPress versions where these functions may not exist.

This follows the established pattern used by other block supports in this directory, e.g., block-style-variations.php, elements.php, layout.php, and duotone.php.

Testing Instructions

  1. Activate the Gutenberg plugin.
  2. Add a block (e.g., a Paragraph block) with custom CSS via the block's "Additional CSS" panel in the editor.
  3. View the page on the frontend.
  4. Inspect the page source — confirm the custom CSS styles appear only once, not duplicated.

Screenshots

Before After
Screenshot 2026-02-25 at 8 39 46 am Screenshot 2026-02-25 at 8 40 27 am

@aaronrobertshaw aaronrobertshaw self-assigned this Feb 25, 2026
@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels Feb 25, 2026
Copy link
Copy Markdown
Contributor

@im3dabasia im3dabasia left a comment

Choose a reason for hiding this comment

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

LGTM ✅

Thanks for the PR! Works as expected. In my testing, the second CSS snippet turned out to be redundant and wasn't being used anywhere. It also tests well against the global styles.

Before After
Image Image

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

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.

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

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

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

Copy link
Copy Markdown
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

LGTM, too 👍

@ramonjd
Copy link
Copy Markdown
Member

ramonjd commented Feb 26, 2026

Good spotting! 🙇🏻

@ramonjd ramonjd merged commit 48d14ff into trunk Feb 26, 2026
60 of 65 checks passed
@ramonjd ramonjd deleted the fix/duplicate-custom-css-for-block-instance branch February 26, 2026 06:13
@github-actions github-actions bot added this to the Gutenberg 22.7 milestone Feb 26, 2026
@talldan
Copy link
Copy Markdown
Contributor

talldan commented Feb 26, 2026

I noticed there was also an issue (#75828) which I've closed as completed.

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

Labels

[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants