Multiple rendering causing a ul more I had following code in template.php this is in function bartik_process_page(&amp;$variables) 

 $main_menu_tree = menu_tree_all_data('main-menu');
 $variables['main_menu_expanded'] = menu_tree_output($main_menu_tree);


and in page.tpl.php

&lt;?php if ($main_menu): ?&gt;
                    &lt;div id="main-menu" class="navigation"&gt;
                        &lt;?php print render($main_menu_expanded); ?&gt;
                    &lt;/div&gt; &lt;!-- /#main-menu --&gt;
        &lt;?php endif; ?&gt; 
                          &lt;?php if ($main_menu): ?&gt;
                    &lt;div id="main-menu" class="navigation"&gt;
                        &lt;?php print render($main_menu_expanded); ?&gt;
                    &lt;/div&gt; &lt;!-- /#main-menu --&gt;
        &lt;?php endif; ?&gt; 
                            &lt;?php if ($main_menu): ?&gt;
                    &lt;div id="main-menu" class="navigation"&gt;
                        &lt;?php print render($main_menu_expanded); ?&gt;
                    &lt;/div&gt; &lt;!-- /#main-menu --&gt;
        &lt;?php endif; ?&gt; 


and output it is like this in bartik

1

    &lt;ul class="menu clearfix"&gt;&lt;li class="first last leaf"&gt;&lt;a href="/ji/" class="active"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;       


2. Now u can see i m getting &lt;ul class="menu"&gt; extra

&lt;div class="navigation" id="main-menu"&gt;
                        &lt;ul class="menu clearfix"&gt;&lt;ul class="menu clearfix"&gt;&lt;li class="first last leaf"&gt;&lt;a class="active" href="/ji/"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;                    &lt;/div&gt; 


Any idea how can i stop it
I have found the answer of it since in render variables are passed by reference https://api.drupal.org/api/drupal/includes!common.inc/function/render/7

so i was passing $main_menu_expanded multiple times in render which was culprit.

Fix is

$variables['main_menu_expanded'] = render(menu_tree_output($main_menu_tree));
&lt;?php if ($main_menu): ?&gt;
                    &lt;div id="main-menu" class="navigation"&gt;
                        &lt;?php print ($main_menu_expanded); ?&gt;
                    &lt;/div&gt; &lt;!-- /#main-menu --&gt;
&lt;?php endif; ?&gt;

&lt;?php if ($main_menu): ?&gt;
                    &lt;div id="main-menu" class="navigation"&gt;
                        &lt;?php print ($main_menu_expanded); ?&gt;
                    &lt;/div&gt; &lt;!-- /#main-menu --&gt;
&lt;?php endif; ?&gt;


Now i dont get extra ul