S
S
Sergey2018-09-07 00:02:37
WordPress
Sergey, 2018-09-07 00:02:37

How to assign the active class to the menu item of the current custom post in WordPress?

5b91929f72e87849959228.jpeg
Custom post type page. It is necessary in this menu to add the active class to the corresponding item in the menu. That is, you need to understand what post we are on and assign the active class to the corresponding menu in .
The structure of this menu is as follows:

<ul>
     <li class="сюда нужен класс"><a href="#"></a></li>
     <li ><a href="#"></a></li>
</ul>

--------------
There are also other custom entries, there you also need to assign the active class, but there is already a two-level menu and the parent needs the active class. The structure is as follows:
<ul>
  <li class="сюда нужен класс">
    <span>Заголовок 1</span>
    <ul>
      <li><a href="#"></a></li>
    </ul>
  </li>
  <li>
    <span>Заголовок 2</span>
    <ul>
      <li><a href="#"></a></li>
    </ul>
  </li>
</ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d1mapetrenko27, 2018-09-07
@d1mapetrenko27

WordPress has a native css class: current_menu_item

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question