WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show dynamic sidebar content on menu item (within <li></li> tag) but unfortunately sidebar content show top of <nav></nav> tag, i mean top of the menu and where i call dynamic side bar here show result 1. I don't find any suggestion related this problem. So please, any one can help me. Thank you. here is my menu code

1. Menu code:   

                          wp_nav_menu( array('menu' => 'primary-menu' ));
                        } else {
                            $pages = wp_list_pages('sort_column=menu_order&title_li=&echo=0');
                            $pages = str_replace(array('<li class="page_item">', '</li>'), '', $pages);
                            echo "<ul>".$pages."<li><a href='#'></a></li></ul>";
                        } ?>

2. dynamic side bar adding code:

    add_filter('wp_nav_menu_items', 'your_custom_menu_item', 10, 2);

    function your_custom_menu_item($items, $args) {
        if ($args->menu == 'primary-menu') {
            return $items .= '

    <li><a href="#">What is blank</a>
    '.dynamic_sidebar('Mega Menu').'
    <li><a href="#" class="icon_menu fi-shopping-cart"></a></li>
    <li><a href="#" id="pm_search" class="icon_menu fi-magnifying-glass"></a>
        <div id="searc_box">
            <div id="searc_wrapper">
                <form role="search" method="get" class="search-form" action="'.home_url( '/' ).'">
                    <input type="search" class="search-field" placeholder="Search …" value="" name="s"/>
                    <input type="submit" class="search-submit postfix" value="Search" />

        return $items;

3. Result code:

<li><a href="#">What is blank</a>1</li>
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.