The Wordpress Walker_Nav_Menu class was a bit crowded, the goal was to replace the standard menu classes with its own.
Here is the code:
function start_el(&$output, $item, $depth, $args) { // здесь дописываю к массиву с классами свои значения. // назначаем классы li-элементу и выводим его $item->classes['my_item_class'] = 'page-header__nav_item'; // класс li элемента $item->classes['my_link_class'] = 'page-header__nav_link'; // класс a элемента if($item->current) { $item->classes['my_current_class'] = 'page-header__nav_link--active'; // класс a элемента текущего пункта меню } $class_names = ' class="' .esc_attr( $item->classes['my_item_class'] .' '. $item->classes['parent_class'] ). '"'; $output.= '<li ' .$class_names. '>'; // назначаем атрибуты a-элементу $attributes.= !empty( $item->url ) ? ' href="' .esc_attr($item->url). '" class="' . $item->classes['my_link_class'] . ' ' . $item->classes['my_current_class'] . '" ' : ''; $item_output = $args->before; array with classes $item->classes , after these manipulations it looks like:
Array ( [0] => [1] => menu-item [2] => menu-item-type-custom [3] => menu-item-object-custom [4] => current-menu-item [5] => current_page_item [6] => menu-item-home [my_item_class] => page-header__nav_item [my_link_class] => page-header__nav_link [my_current_class] => page-header__nav_link--active ) An error occurs:
Warning: Illegal string offset 'my_item_class' in /var/www/vhosts/u0205156.plsk.regruhosting.ru/blog.itconcentrate.pw/wp-content/themes/gragon/functions.php on line 221
Well, respectively, for all the elements of the classes array added by me.
What is the problem?
print_r($item->classes)it shows !!! Classes are added to the menu items, onlywarningclimbs. - pepel_xD