@@ -41,6 +41,18 @@ class WP_Navigation_Block_Renderer {
4141 */
4242 private static $ seen_menu_names = array ();
4343
44+ /**
45+ * Returns whether the navigation overlay experiment is enabled.
46+ *
47+ * @since 6.5.0
48+ *
49+ * @return bool Returns whether the navigation overlay experiment is enabled.
50+ */
51+ private static function is_overlay_experiment_enabled () {
52+ $ gutenberg_experiments = get_option ( 'gutenberg-experiments ' );
53+ return $ gutenberg_experiments && array_key_exists ( 'gutenberg-customizable-navigation-overlays ' , $ gutenberg_experiments );
54+ }
55+
4456 /**
4557 * Returns whether or not this is responsive navigation.
4658 *
@@ -712,14 +724,28 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
712724
713725 // Build the content markup with desktop and overlay containers.
714726 $ content_markup = '' ;
727+ $ is_overlay_experiment_enabled = static ::is_overlay_experiment_enabled ();
728+
715729 if ( $ has_overlay && ! empty ( $ overlay_blocks_html ) ) {
716730 // Render both desktop and overlay blocks in separate containers.
717- $ content_markup = sprintf (
718- '<div class="wp-block-navigation__desktop-container">%1$s</div>
719- <div class="wp-block-navigation__overlay-container" aria-hidden="true">%2$s</div> ' ,
720- $ inner_blocks_html ,
721- $ overlay_blocks_html
722- );
731+ // IMPORTANT: The desktop container wrapper is gated behind the experiment to ensure
732+ // backward compatibility. Without the experiment enabled, the desktop navigation
733+ // should not be wrapped in a container div, maintaining the exact same markup structure
734+ // as before this feature. This prevents any potential CSS or layout issues for users
735+ // who don't have the experiment enabled.
736+ if ( $ is_overlay_experiment_enabled ) {
737+ $ content_markup = sprintf (
738+ '<div class="wp-block-navigation__desktop-container">%1$s</div>
739+ <div class="wp-block-navigation__overlay-container" aria-hidden="true">%2$s</div> ' ,
740+ $ inner_blocks_html ,
741+ $ overlay_blocks_html
742+ );
743+ } else {
744+ // Experiment not enabled: Don't wrap desktop navigation to maintain backward compatibility.
745+ // Render desktop blocks without wrapper (maintains exact same markup as before this feature).
746+ // Note: UI prevents overlay selection when experiment is off, but handle gracefully if attribute exists.
747+ $ content_markup = $ inner_blocks_html ;
748+ }
723749 } else {
724750 // No overlay selected, use existing behavior.
725751 $ content_markup = $ inner_blocks_html ;
0 commit comments