diff --git a/packages/block-library/src/navigation-menu/index.php b/packages/block-library/src/navigation-menu/index.php index 2426d4bb6b3635..fc38984e1c025d 100644 --- a/packages/block-library/src/navigation-menu/index.php +++ b/packages/block-library/src/navigation-menu/index.php @@ -49,20 +49,18 @@ function build_css_colors( $attributes ) { * @return string Returns the post content with the legacy widget added. */ function render_block_navigation_menu( $attributes, $content, $block ) { - $colors = build_css_colors( $attributes ); - $class_attribute = sprintf( ' class="%s"', esc_attr( $colors['css_classes'] ? 'wp-block-navigation-menu ' . $colors['css_classes'] : 'wp-block-navigation-menu' ) ); - $style_attribute = $colors['inline_styles'] ? sprintf( ' style="%s"', esc_attr( $colors['inline_styles'] ) ) : ''; + $colors = build_css_colors( $attributes ); + $classes = array( 'wp-block-navigation-menu', $colors['css_classes'] ); + if ( ! empty( $attributes['className'] ) ) { + $classes[] = $attributes['className']; + } + + $classes = join( ' ', array_filter( $classes ) ); + return sprintf( - implode( - "\n", - array( - '', - ' %s', - '', - ) - ), - $class_attribute, - $style_attribute, + '', + esc_attr( $classes ), + $colors['inline_styles'] ? sprintf( 'style="%s"', esc_attr( $colors['inline_styles'] ) ) : '', build_navigation_menu_html( $block, $colors ) ); }