Dynamic_sidebar inside wp_nav_menu
Вопрос
I have Menu created by wp_nav_menu. Inside it, I want to set dynamic_sidebar but wp_nav_menu instead of displaying the content, throws 1.
Have everyone some tips for display sidebar inside wp_nav_menu? I have to add dynamic_sidebar inside menu it's important.
Inside walker I placed the code:
$item_output .= '
<div class="recipes__dropdown">
<div class="container">
<div class="dropdown__content">
<div class="row">' . dynamic_sidebar( 'recipes-dropdown' ) . '</div>
</div>
</div>
</div>';
Have you any suggestions how include dynamic sidebar inside wp_nav_menu?
Решение
You can add extra items in menu like
add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if ($args->theme_location == '[YOUR-MENU-LOCATION]') {
$items .= '--YOUR EXTRA STUFF HERE--';
}
return $items;
}
Hope it will help!
Другие советы
The point is that dynamic_sidebar
does echo
and we need to get its content not echo
it inside wp_nav_menu
.
Try to do like this:
ob_start();
$sidebar = dynamic_sidebar( 'recipes-dropdown' );
$sidebar = ob_get_contents();
$item_output .= $sidebar;
ob_end_clean();
This helped me to make it work.
Не связан с wordpress.stackexchange