diff --git includes/menu.inc includes/menu.inc
index fb61fd3..cc5eeed 100644
--- includes/menu.inc
+++ includes/menu.inc
@@ -2186,17 +2186,13 @@ function menu_local_tabs() {
 function theme_menu_local_tasks(&$variables) {
   $output = '';
 
-  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']);
+  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>';
   }
 
   return $output;
diff --git modules/system/page.tpl.php modules/system/page.tpl.php
index 1092da0..5230daf 100644
--- modules/system/page.tpl.php
+++ modules/system/page.tpl.php
@@ -123,7 +123,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): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?>
+        <?php if ($tabs = render($tabs)): ?><div class="tabs"><?php print $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 themes/bartik/templates/page.tpl.php themes/bartik/templates/page.tpl.php
index ed18127..958e8c2 100644
--- themes/bartik/templates/page.tpl.php
+++ themes/bartik/templates/page.tpl.php
@@ -193,9 +193,9 @@
         </h1>
       <?php endif; ?>
       <?php print render($title_suffix); ?>
-      <?php if ($tabs): ?>
+      <?php if ($tabs = render($tabs)): ?>
         <div class="tabs">
-          <?php print render($tabs); ?>
+          <?php print $tabs; ?>
         </div>
       <?php endif; ?>
       <?php print render($page['help']); ?>
diff --git themes/garland/page.tpl.php themes/garland/page.tpl.php
index 4857a67..ce7674c 100644
--- themes/garland/page.tpl.php
+++ themes/garland/page.tpl.php
@@ -47,7 +47,7 @@
             <h1<?php print $tabs ? ' class="with-tabs"' : '' ?>><?php print $title ?></h1>
           <?php endif; ?>
           <?php print render($title_suffix); ?>
-          <?php if ($tabs): ?><?php print render($tabs); ?></div><?php endif; ?>
+          <?php if ($tabs = render($tabs)): ?><?php print $tabs; ?></div><?php endif; ?>
           <?php print render($tabs2); ?>
           <?php print $messages; ?>
           <?php print render($page['help']); ?>
