diff --git a/includes/menu.inc b/includes/menu.inc
index 7423c994351c2d3e488a4e7107d02cbede14d336..3e775db7ba93a41543b4291919bf7a1dccafa761 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -2172,13 +2172,17 @@ function menu_local_tabs() {
 function theme_menu_local_tasks(&$variables) {
   $output = '';
 
-  if ($primary = drupal_render($variables['primary'])) {
-    $output .= '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
-    $output .= '<ul class="tabs primary">' . $primary . '</ul>';
-  }
-  if ($secondary = drupal_render($variables['secondary'])) {
-    $output .= '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
-    $output .= '<ul class="tabs secondary">' . $secondary . '</ul>';
+  if (!empty($variables['primary'])) {
+    $variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
+    $variables['primary']['#prefix'] .= '<ul class="tabs primary">';
+    $variables['primary']['#suffix'] = '</ul>';
+    $output .= drupal_render($variables['primary']);
+  }
+  if (!empty($variables['secondary'])) {
+    $variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
+    $variables['secondary']['#prefix'] .= '<ul class="tabs secondary">';
+    $variables['secondary']['#suffix'] = '</ul>';
+    $output .= drupal_render($variables['secondary']);
   }
 
   return $output;
diff --git a/modules/system/page.tpl.php b/modules/system/page.tpl.php
index f765f95244bd9b299b804b7a8e0221a9e21350d6..ca9273cd6632f0540a5389b5f61d3c5290f4726a 100644
--- a/modules/system/page.tpl.php
+++ b/modules/system/page.tpl.php
@@ -124,7 +124,7 @@
         <?php print render($title_prefix); ?>
         <?php if ($title): ?><h1 class="title" id="page-title"><?php print $title; ?></h1><?php endif; ?>
         <?php print render($title_suffix); ?>
-        <?php if ($tabs = render($tabs)): ?><div class="tabs"><?php print $tabs; ?></div><?php endif; ?>
+        <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?>
         <?php print render($page['help']); ?>
         <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?>
         <?php print render($page['content']); ?>
diff --git a/themes/bartik/templates/page.tpl.php b/themes/bartik/templates/page.tpl.php
index ec806245450985528e7ebcb9f56e27324e4f423b..7b0f99097a0e40b2f6944b61584951430b8a94fe 100644
--- a/themes/bartik/templates/page.tpl.php
+++ b/themes/bartik/templates/page.tpl.php
@@ -192,9 +192,9 @@
         </h1>
       <?php endif; ?>
       <?php print render($title_suffix); ?>
-      <?php if ($tabs = render($tabs)): ?>
+      <?php if ($tabs): ?>
         <div class="tabs">
-          <?php print $tabs; ?>
+          <?php print render($tabs); ?>
         </div>
       <?php endif; ?>
       <?php print render($page['help']); ?>
diff --git a/themes/garland/page.tpl.php b/themes/garland/page.tpl.php
index cc72b0829242c2b0bc8470584ecfcdb1d7102e33..326255cd4ef894a9dcbf6ecf23cae5d76143e51a 100644
--- a/themes/garland/page.tpl.php
+++ b/themes/garland/page.tpl.php
@@ -46,7 +46,7 @@
             <h1<?php print $tabs ? ' class="with-tabs"' : '' ?>><?php print $title ?></h1>
           <?php endif; ?>
           <?php print render($title_suffix); ?>
-          <?php if ($tabs = render($tabs)): ?><?php print $tabs; ?></div><?php endif; ?>
+          <?php if ($tabs): ?><?php print render($tabs); ?></div><?php endif; ?>
           <?php print render($tabs2); ?>
           <?php print $messages; ?>
           <?php print render($page['help']); ?>