diff --git a/bootstrap_barrio.theme b/bootstrap_barrio.theme
index 8b9dd2c63ef2264373d1f563b0fe151b8d46620b..45693fa97813937abe7ef33b22cb6c5298dda1dc 100644
--- a/bootstrap_barrio.theme
+++ b/bootstrap_barrio.theme
@@ -348,7 +348,7 @@ function bootstrap_barrio_preprocess_region(&$variables) {
  * Implements hook_preprocess_HOOK() for block.html.twig.
  */
 function bootstrap_barrio_preprocess_block(&$variables) {
-  if ($variables['base_plugin_id'] == 'system_menu_block') {
+  if ($variables['base_plugin_id'] == 'system_menu_block' && isset($variables['attributes']['id'])) {
     $variables['content']['#attributes']['block'] = $variables['attributes']['id'];
   }
   // Add a clearfix class to system branding blocks.