Answer the question
In order to leave comments, you need to log in
Why menu item in Wordpress is not marked as active?
Good afternoon.
In the main menu of a wordpress site, menu items leading to the post archive are not marked as active when viewing a single post page. How can this be set up?
The link to the entry page looks like domain.com/services/service-1
Answer the question
In order to leave comments, you need to log in
Look at the source code of the menu, see the class in it at the active menu item, for example, current_page_item , cover the lazy ass of the theme creator who did not write styles for it. You write them down yourself.
For example so.
Profit!!!
.current_page_item > a{ color: red}
Yes, the problem was in the template, but different.
By default, in the menu item traversal class, which extends the Walker_Nav_menu class, the condition for determining the item as active was as follows:
if(in_array('current-menu-item', $item->classes)) ...
(strpos($item->url, $post->post_name) > 0) || // для стандартных страниц
(strpos($item->url, $post->post_type) > 0) || // для записей пользовательских типов
(get_the_category($post)[0]->name == $item->title) // для стандартных записей рубрики
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question