User element of the active message type

I created my own type of message called "command" and added a link to the archive page in the WP menu. As soon as the user clicks on him, he is shown to all team members, and the current page is highlighted in the menu. But when I click on an individual team member, his page opens, and the "Team" in the menu no longer stands out, and it should be.

Here's how it displays when the command page opens:

<li id="menu-item-17" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item active"> <a href="http://localhost:8888/site/team/">Team</a> </li> 

and this is what I get on the menu when I open a separate member page:

 <li id="menu-item-17" class="menu-item menu-item-type-custom menu-item-object-custom"> <a href="http://localhost:8888/site/team/">Team</a> </li> 

Since I'm not a PHP developer, I don't know how to make it work, any suggestion would be highly appreciated :)

+5
source share
1 answer

I got it to work for me, taken and edited, here . When I have a bonsai, change it to your own message type. When I put "menu-item-299", change it to the identifier of your menu item that you want to keep highlighted.

 function change_page_menu_classes($menu) { global $post; if (get_post_type($post) == 'bonsai') { $menu = str_replace( 'current-menu-item', '', $menu ); // remove all current_page_parent classes $menu = str_replace( 'menu-item-299', 'menu-item-299 current-menu-item', $menu ); // add the current_page_parent class to the page you want } return $menu; } add_filter( 'nav_menu_css_class', 'change_page_menu_classes', 10,2 ); 

Let me know if you have problems, because maybe they amaze me :)

+6
source

Source: https://habr.com/ru/post/1211883/


All Articles