diff --git a/core/includes/common.inc b/core/includes/common.inc
index a4805c0..cc60f4f 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -3728,7 +3728,13 @@ function drupal_render_page($page) {
  *   - If this element has an array of #theme_wrappers defined and
  *     #render_children is not set, #children is then re-rendered by passing the
  *     element in its current state to theme() successively for each item in
- *     #theme_wrappers.
+ *     #theme_wrappers. Since #theme and #theme_wrappers hooks often define
+ *     variables with the same names and this can cause conflicts, it is
+ *     possible to explicitly specify which theme wrapper hook each attribute is
+ *     passed to by renaming it to #wrapper_wrappername_attributename. For
+ *     example, to ensure an attribute that would normally be named #attributes
+ *     is only used by the 'container' theme wrapper, it can be renamed to
+ *     #wrapper_container_attributes.
  *   - If this element has an array of #post_render functions defined, they are
  *     called sequentially to modify the rendered #children. Unlike #pre_render
  *     functions, #post_render functions are passed both the rendered #children
@@ -3858,7 +3864,21 @@ function drupal_render(&$elements) {
   // #theme_wrappers function(s) to prevent infinite recursion.
   if (isset($elements['#theme_wrappers']) && !isset($elements['#render_children'])) {
     foreach ($elements['#theme_wrappers'] as $theme_wrapper) {
-      $elements['#children'] = theme($theme_wrapper, $elements);
+      // If #theme and #theme_wrappers have a namespace conflict and expect two
+      // or more different values under a single attribute we disambiguate on
+      // behalf of #theme_wrappers by allowing wrapper specific overrides for
+      // element attributes in the format #wrapper_wrappername_attributename to
+      // override #attributename.
+      $wrapper_elements = $elements;
+      foreach ($wrapper_elements as $key => $value) {
+        if (strstr($key, '#wrapper_' . $theme_wrapper . '_')) {
+          $strlen = strlen('#wrapper_' . $theme_wrapper . '_');
+          $new_key = '#' . substr($key, $strlen);
+          $wrapper_elements[$new_key] = $wrapper_elements[$key];
+          unset($wrapper_elements[$key]);
+        }
+      }
+      $elements['#children'] = theme($theme_wrapper, $wrapper_elements);
     }
   }
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
index ec115e3..5468ed2 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
@@ -73,6 +73,48 @@ function testDrupalRenderBasics() {
         'expected' => '',
       ),
 
+      // Test that #theme and #theme_wrappers can co-exist on an element.
+      array(
+        'name' => '#theme and #theme_wrappers basic',
+        'value' => array(
+          '#theme' => 'common_test_foo',
+          '#foo' => 'foo',
+          '#bar' => 'bar',
+          '#theme_wrappers' => array('container'),
+          '#attributes' => array('class' => 'baz'),
+        ),
+        'expected' => '<div class="baz">foobar</div>',
+      ),
+      // Test that #theme_wrappers can disambiguate element attributes shared
+      // with rendering methods that build #children by using the alternate
+      // #theme_wrappers attribute override syntax
+      // #wrapper_wrappername_attributename.
+      array(
+        'name' => '#theme and #theme_wrappers attribute disambiguation',
+        'value' => array(
+          '#type' => 'link',
+          '#theme_wrappers' => array('container'),
+          '#wrapper_container_attributes' => array('class' => 'baz'),
+          '#attributes' => array('id' => 'foo'),
+          '#href' => 'http://drupal.org',
+          '#title' => 'bar',
+        ),
+        'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>',
+      ),
+      // Test that #theme_wrappers can disambiguate element attributes when the
+      // "base" attribute is not set for #theme.
+      array(
+        'name' => '#theme_wrappers attribute disambiguation with undefined #theme attribute',
+        'value' => array(
+          '#type' => 'link',
+          '#href' => 'http://drupal.org',
+          '#title' => 'foo',
+          '#theme_wrappers' => array('container'),
+          '#wrapper_container_attributes' => array('class' => 'baz'),
+        ),
+        'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>',
+      ),
+
       // Test handling of #markup as a fallback for #theme hooks.
       // Simple #markup with no theme.
       array(
