I have a client that wanted two “main menus” and we needed to programmatically display whichever menu contained the current page. How can I do that?
Ex: We’re on the “About” page. Figure out which of the two menus contains the “About” page and show that one.
Here’s the function I wrote to figure this out. You give it a menu slug/name/ID and post/page ID and it returns
TRUE
if that post/page is in the specified menu andFALSE
otherwise. Then it was just simply a matter of a quick if/else statement to check against the two menus and display the correct one.Example Usage: