It is necessary to display on the page all children of the active menu item. Ie for example, I have <ul class='primary'><li>О нас <ul><li>О компании</li><li>Филиалы</li></ul> </li></ul

That is, if I have moved to the About Us page, then I need to duplicate all the subitems of the About Us item in a separate place on the page.

    1 answer 1

    In function.php register the following code:

     function menu_childs_only( $items, $args ) { global $stitle; // заглобалим переменную, в неё потом сунем имя самого верхнего элемента, для заголовка меню if ( empty($args->childs_only) ) // если параметр не был передан return $items; // обычный вывод меню $newitems = array(); // подготовим пустые массивы $ids = array(); // здесь будут id всех активных пунктов foreach ( $items as $key => $item ) { // пробегаем по каждому элементу, этот if ( $item->current ) { // если элемент активный if ($item->menu_item_parent != 0) { // и если есть родительский элемент $ids[] = $item->menu_item_parent; // пишем его в массив } } } foreach ( $items as $key => $item ) { // пробежим еще раз if (($item->current_item_ancestor || $item->current || in_array('current-post-ancestor', $item->classes))) { // если элемент активный и самый верхний $stitle = $item->title; // запишем заголовок меню static $stitle; // пишем один раз $ids[] = $item->ID; // добавляем его id в массив } if (in_array($item->menu_item_parent, $ids)) { // если id есть среди активных id $newitems[] = $item; // пишем весь элемент в массив новых элементов if ($item->current) { // вот это я не помню для чего, но нужно $ids[] = $item->ID; } } } return $newitems; // возвращаем отфильтрованные элементы меню 

    }

    Call in the place on the page where necessary.