Make WordPress Core

Opened 4 hours ago

Last modified 62 minutes ago

#65335 new feature request

Show a warning message about a commented-out Gutenberg block in the Classic Editor.

Reported by: blackstar1991's profile blackstar1991 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: ui, ui-copy Cc:

Description

What problem does this address?

When a post or page contains Gutenberg block markup inside HTML comments, the Classic Editor can create a misleading editing experience.
https://i.ibb.co/LDGJFFsq/597177196-80e9b120-2aca-45a8-9eb4-5594c2a575ea.png
In the Code/Text tab, the content technically exists because the Gutenberg block markup is present in the post content, for example:

<!-- wp:group {"backgroundColor":"black","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-black-background-color has-background"><!-- wp:gigroute-events/events {"titleStyles":{"textAlign":"center","color":"","fontSize":"24px","fontFamily":"Roboto, sans-serif","fontWeight":"700","lineHeight":"","spacing":{"margin":{"top":"20px","right":"","bottom":"20px","left":""},"padding":{"top":"24px","right":"24px","bottom":"24px","left":"24px"}}},"archiveUrl":"/tourdates/","dateDisplayFormat":"long_date","fullEventClick":true,"className":"bg_cover60 animation-show ","style":{"background":{"backgroundImage":{"url":"http://brothersofmetal.loc/wp-content/uploads/2026/03/bom_fire-large.jpg","id":300,"source":"file","title":"bom_fire-large"},"backgroundSize":"contain","backgroundRepeat":"no-repeat","backgroundPosition":"50% 0%"},"spacing":{"padding":{"bottom":"54px"}}}} /--></div>
<!-- /wp:group -->

However, because this block-related markup is stored inside HTML comments, it may not be visible in the Visual tab of the Classic Editor. As a result, the Visual editor can make the page appear empty or incomplete, even though the post content still contains Gutenberg block data.

This can confuse editors and create two main risks:

Editors may accidentally overwrite or delete existing block content because they assume the page is empty.
Editors may unknowingly keep unused or outdated block markup in the page content, even when it is no longer used visually. This can unnecessarily clutter the page content and may negatively affect content quality, maintenance, or SEO analysis.

The issue is specifically related to WordPress/Gutenberg block comments and serialized block markup, not ordinary HTML comments. A warning should only appear when WordPress block syntax is detected.

What is your proposed solution?

Add a warning or informational notice in the Classic Editor when the post content contains Gutenberg block markup that is present in the Code/Text tab but is not visibly rendered in the Visual tab.

For example, the Classic Editor could display a non-intrusive notice such as:

https://i.ibb.co/yB0fDvgT/597177157-6cd9ddea-a6c2-488e-8d7d-7f3f3b9dcad7.png

This content includes Gutenberg block markup that may be visible in the Code/Text tab but not in the Visual editor. The page may not be empty. Please review the content carefully before overwriting or deleting it.

The detection should focus specifically on WordPress block syntax, such as comments starting with:

<!-- wp:

and should not trigger for regular HTML comments.

This warning would help editors understand that the page may contain hidden block-related content even if the Visual tab appears empty. It would reduce the risk of accidentally removing valid content, while also helping editors identify and clean up unused block markup that is no longer needed.

A possible implementation could be a dismissible admin notice or an inline warning near the Classic Editor content area when block markup is detected in the post content.

Change History (4)

#1 @ankitkumarshah
3 hours ago

Hi @blackstar1991, I was able to reproduce this behavior.

I agree that this can create a confusing editing experience in the Classic Editor. Since Gutenberg block markup is stored inside HTML comments, the Visual tab may appear empty or incomplete even though content still exists in the Text/Code tab.

I think adding a notice would be a good improvement here. Placing a notice directly below the Add Media button could make it visible without interrupting the editing flow.

The notice could appear only when WordPress block syntax (for example <!-- wp:) is detected,
This would help editors understand that the page may still contain Gutenberg block content.

https://i.postimg.cc/nLCcQwsD/Screenshot-2026-05-25-at-12-44-12-PM.png
https://i.postimg.cc/3xLxNHwX/Screenshot-2026-05-25-at-12-44-19-PM.png

#2 @sabernhardt
3 hours ago

  • Component changed from General to Editor
  • Focuses ui-copy added; accessibility css removed
  • Version 7.0 deleted

I suggest adding an admin notice, immediately before the <form element, in edit-form-advanced.php.

if ( str_contains( $post->post_content, '<!-- wp:' ) ) :
	wp_admin_notice(
		__( 'This content includes blocks, and some of the block content might not display in the Visual editor. Please review the content carefully before overwriting or deleting it.' ),
		array(
			'type' => 'warning',
		)
	);
endif;

#4 @dhrumilk
62 minutes ago

<?php
if (
	isset( $post->post_content ) &&
	str_contains( (string) $post->post_content, '<!-- wp:' )
) {
	wp_admin_notice(
		        __(
			'This content includes blocks, and some of the block content might not display in the Visual editor. Please review the content carefully before overwriting or deleting it.',
			'your-text-domain'
		),
		array(
			'type'        => 'warning',
			'dismissible' => true,
		)
	);
}
?>

This code follows WordPress best practices by safely checking if block content exists before running the logic, which prevents PHP warnings and improves stability. It also uses proper escaping and translation functions to keep the admin notice secure, maintainable, and translation-ready.

This is my suggestion for improving the code by following WordPress coding standards, adding safer checks, and improving maintainability.

Note: See TracTickets for help on using tickets.