diff --git a/core/includes/common.inc b/core/includes/common.inc
index c482a13..3cf6aa3 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4018,6 +4018,51 @@ function render(&$element) {
 }
 
 /**
+ * Checks that a render array has content that can be rendered.
+ *
+ * @param $element
+ *   The renderable element to check.
+ *
+ * @param $offset
+ *   The key of the child to check.
+ *
+ * @return bool
+ *   TRUE if the element has access granted and content that can be rendered.
+ */
+function has_render_content($element, $offset) {
+  if (!$element || !$offset || empty($element[$offset])) {
+    return FALSE;
+  }
+  // Stop if access is explicitly denied.
+  if (isset($element[$offset]['#access']) && !$element[$offset]['#access']) {
+    return FALSE;
+  }
+  // Check for at least one "visible" child.
+  $children = element_get_visible_children($element[$offset]);
+  if (!empty($children)) {
+    $child_checks = array();
+    foreach ($children as $key) {
+      if (has_render_content($element[$offset], $key)) {
+        $child_checks[$key] = TRUE;
+        continue;
+      }
+    }
+    return !empty($child_checks);
+  }
+  // Check that this terminal element can be rendered.
+  else {
+    // This is a last child.  Can it be rendered?  Let's see (the old way).
+    // Ex: If there's block content in $element['sidebar_first']['stark.tools'],
+    // follow drupal_render() below to see what happens.  I see that $elements
+    // does contain stark.tools block content, but the evaluation in drupal_render()
+    // somehow strangely causes $elements to then be set as null.
+    // Q: [How, for others] does drupal_render() evaluate this offset as NULL?
+    $rendered_offset = drupal_render($element[$offset]);
+    return $rendered_offset;
+  }
+}
+
+/**
  * Hides an element from later rendering.
  *
  * The first time render() or drupal_render() is called on an element tree,
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index e49bb76..c440a39 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2512,14 +2512,14 @@ function template_preprocess_html(&$variables) {
   $variables['attributes']['class'][] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
 
   // Add information about the number of sidebars.
-  if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
+  if (has_render_content($variables['page'], 'sidebar_first') && has_render_content($variables['page'], 'sidebar_second')) {
     $variables['attributes']['class'][] = 'two-sidebars';
   }
-  elseif (!empty($variables['page']['sidebar_first'])) {
+  elseif (has_render_content($variables['page'], 'sidebar_first')) {
     $variables['attributes']['class'][] = 'one-sidebar';
     $variables['attributes']['class'][] = 'sidebar-first';
   }
-  elseif (!empty($variables['page']['sidebar_second'])) {
+  elseif (has_render_content($variables['page'], 'sidebar_second')) {
     $variables['attributes']['class'][] = 'one-sidebar';
     $variables['attributes']['class'][] = 'sidebar-second';
   }
