Answer the question
In order to leave comments, you need to log in
How to properly add a menu in WP 5.8 layout?
Can't add correct menu in WP. In header.php I add:
<? wp_nav_menu([
'menu' => 'head_menu',
'container' => false,
'menu_class' => 'top-menu',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'item_wrap' => '<ul class="header__nav">%3$s</ul>',
'depth' => 1
]); ?>
register_nav_menus( array(
'head_menu' => 'Меню в шапке'
) );
add_theme_support( 'menus' );
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\www\mebelsheldon.ru\wp-includes\class-walker-nav-menu.php on line 205
<li id="menu-item-125" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-125"><a>О компании</a></li>
Answer the question
In order to leave comments, you need to log in
Understood. Although there was an error before the function, I made the connection, as from the default theme, through the after_setup_theme action. Now everything works. The menu is displayed :)
The problem was in the hook, apparently I wrote it incorrectly ..
// Мой первый фильтр
add_filter ('nav_menu_link_attributes', 'filter_nav_menu_link_attributes', 10,3);
function filter_nav_menu_link_attributes ( $atts, $item, $args) {
if ($args->menu === 'Main') {
$atts['class'] = 'header__nav-item';
if ( $item->current) {
$atts['class'] .= 'header__nav-item-active';
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question