A
A
Alexander Sharomet2014-02-25 20:25:00
CMS
Alexander Sharomet, 2014-02-25 20:25:00

How to remove extra classes from menu items in Wordpress?

Hello.
I created my own menu in wordpress
like this:

wp_nav_menu(array(
 'menu' => '', // название меню
 'container' => 'div', // контейнер для меню, по умолчанию 'div', в нашем случае ставим 'nav', пустая строка - нет контейнера
 'container_class' => 'collapse navbar-collapse', // класс для контейнера
 'container_id' => 'collapse-1', // id для контейнера
 'menu_class' => 'nav navbar-nav', // класс для меню
 'menu_id' => '', // id для меню
));

But here's the problem: now each menu item contains many classes. Is it normal or not?
<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-6 current_page_item menu-item-14" id="menu-item-14"><a href="http://localhost/ышеу">Главная</a></li>

menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-6 current_page_item menu-item-14 - isn't that too much?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
Timur Kalimullin, 2014-02-25
@sharomet

Filter on nav_menu_css_class
something like:

function my_remove_all_class_item($classes, $item) {
  $classes = '';
  return $classes;
}
add_filter('nav_menu_css_class', 'my_remove_all_class_item', 10, 2 );

T
Timur Kalimullin, 2014-02-25
@ZetRider

If suddenly id bothers you:
add_filter('nav_menu_item_id', '__return_false');

R
Ruslan, 2014-02-25
@rOOse

+1 @Synoptic It's better to change the layout than to remove it from the VP

L
Leonid Smirnov, 2019-03-11
@SunyJun

Here is a detailed description of how to remove classes and id from links - https://www.pandoge.com/haki/udalyaem-class-i-id-i...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question