Деление WordPress меню пополам
<?php
add_filter( 'wp_nav_menu_objects', function ( $menu_items, $args ) {
if ( $args->theme_location !== 'menu-1' ) {
return $menu_items;
}
static $average_cnt = null;
static $items = [];
if ( $average_cnt === null ) {
$average_cnt = ceil( count( array_filter( $menu_items, function ( $item ) {
return ! $item->menu_item_parent;
} ) ) / 2 );
$cnt = 1;
foreach ( $menu_items as $i => $item ) {
if ( $average_cnt >= $cnt ) {
if ( ! $item->menu_item_parent ) {
++ $cnt;
}
$items['left'][ $i ] = $item;
} else {
$items['right'][ $i ] = $item;
}
}
}
return $items[ $args->side ];
}, 10, 2 );
wp_nav_menu( [
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
'side' => 'left',
] );
echo "\n---- ЛОГО -----\n";
wp_nav_menu( [
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
'side' => 'right',
] );
?>