I'm looking for a custom permalink plugin that is able to interact with menu classes.

For instance, I have a menu that includes the parent website.com/shop as one of its list items. If a page, say website.com/shop/product, includes that menu, the list item for website.com/shop will get a class, something like current-page-ancestor. This is useful for styling that link so users know what section of the website they are on.

But I will have pages whose parent will not be website.com/shop (a feature I can't change), but I want it to appear that website.com/shop is the parent. For instance, the page is website.com/foo/product-2. I'm currently using the Custom Permalinks plugin to change the permalink to website.com/shop/product-2. But in doing this, the menu does not recognize that website.com/shop is the parent, and no class is added to the menu's list item.

Is there any workaround for this, or does anyone know of a custom permalinks plugin that would support menu ancestry?

Try this to see how the objects that make up a menu are constructed. Perhaps it will shed some light on how you can manipulate menu output. Look at things like menu_item_parent and object_id to see how menu items are related to each other and the posts / pages they represent. Warning- do not do this on a live site!

Okay, so that worked well (although I'm not 100% clear how). But I'd like to add another step if I may. This may be another part of the function. Am I able to add current-page-ancestor to a menu list item based upon different sub-parent pages. e.g. website.com/shop/new/product and website.com/shop/used/product. Where the menu would have Shop -> New | Used and the individual product page would determine whether New or Used got the current-page-ancestor class? Hope that's clear!
–
Timothy DJan 28 '13 at 19:46

for that you'd probably want either the nav_menu_objects filter, a custom walker, or to build the menu manually via wp_get_nav_menu_items. See my edit above for some code that will maybe help you understand how WordPress stores menu items and builds the menu.
–
MiloJan 28 '13 at 20:22

another thought - if you're adding items to a nav menu, WP should be inserting the proper parent / ancestor classes if the items are children in the nav menu, regardless of whether or not they're actually related to each other naturally.
–
MiloJan 28 '13 at 20:32

I understand now how the menus are built and why your code works, so thank you for that inspector code. To your second thought: the product children aren't part of the menu, only the parents are (i.e. 'Shop' and 'New'|'Used'). I believe Wordpress is having troubling recognizing the product pages as children because they have custom permalinks and their original parent is an entirely different page. Is there some way to hook into the new permalink to get a value that might match one of the menu item titles?
–
Timothy DJan 28 '13 at 21:46

Do you have a piece of 'inspector' code that will let me see the post object for the current product page so perhaps I can find a value that will help me select which menu item it is a part of? Just like the code you gave me to see the menu construction.
–
Timothy DJan 28 '13 at 21:50

Here was the final solution I came up with. I spent a lot of looking into whether I could change the the custom post type "product" to hierarchical and set its page parent appropriately so that the menus would add the correct ancestor classes naturally. But I hit a road block and eventually came back to a solution based on the new permalink.

So I imagine this should work for anyone who is aiming to fake a page parent hierarchy when using custom permalinks.

We get the current page url (set by the custom permalinks plugin), then strip it down to the path and save it as the $currentDirPath variable. Then we evaluate whether a menu item's url path is contained within the $currentDirPath, and if so we add the current-page-ancestor class.