@@ -1642,6 +1642,12 @@ protected function get_layout_styles( $block_metadata, $types = array() ) {
16421642 return $ block_rules ;
16431643 }
16441644
1645+ // Skip outputting layout styles for classic themes without theme.json.
1646+ // These styles are only relevant for block themes and themes using theme.json.
1647+ if ( ! wp_is_block_theme () && ! wp_theme_has_theme_json () ) {
1648+ return $ block_rules ;
1649+ }
1650+
16451651 if ( isset ( $ block_metadata ['name ' ] ) ) {
16461652 $ block_type = WP_Block_Type_Registry::get_instance ()->get_registered ( $ block_metadata ['name ' ] );
16471653 if ( ! block_has_support ( $ block_type , 'layout ' , false ) && ! block_has_support ( $ block_type , '__experimentalLayout ' , false ) ) {
@@ -3107,9 +3113,13 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
31073113 $ css .= '.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) > .alignfull { margin-left: 0; margin-right: 0; } ' ;
31083114 }
31093115
3110- $ css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; } ' ;
3111- $ css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; } ' ;
3112- $ css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; } ' ;
3116+ // Skip outputting alignment styles for classic themes without theme.json.
3117+ // These styles target .wp-site-blocks which is only used by block themes.
3118+ if ( wp_is_block_theme () || wp_theme_has_theme_json () ) {
3119+ $ css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; } ' ;
3120+ $ css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; } ' ;
3121+ $ css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; } ' ;
3122+ }
31133123
31143124 // Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.
31153125 if ( isset ( $ this ->theme_json ['settings ' ]['spacing ' ]['blockGap ' ] ) ) {
0 commit comments