So, I want to make a side menu in WordPress.

It should display:
1) all the first-level links
2) the full “path” to the link that is currently selected

I found out that thanks to the WordPress CSS menu class structure I can emulate the behavior I want to get with this code:

ul#menu-test ul {display:none;}
ul#menu-test li.current-menu-ancestor > ul {display:block;}
ul#menu-test li.current-menu-item > ul {display:block;}
ul#menu-test li.current-menu-item > a {background-color:yellow;}

But I don’t want to repeat the whole menu again and just trim it with the CSS, I just want to physically display only the items I really need.

Can I somehow emulate this behavior in PHP? I can pre-fetch the full menu in text format, if that matters.

Read more here: emulate CSS in PHP?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: