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?
Edit
I feel like I'm right there, but missing one thing...
function getUrl() {
$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
$url .= $_SERVER["REQUEST_URI"];
return $url;
}
function getDir($foo) {
$url = $foo;
$info = parse_url($url);
$dir = dirname($info["path"]);
return $dir;
}
function wpa83498_nav_class( $classes, $item ){
// if Shop is the current menu item being output
// and we're viewing a single product post type
$currentDirPath = getDir(getUrl());
if( ('Sales' == $item->title && is_singular( 'product' )) || (parse_url($item->url, PHP_URL_PATH) == $currentDirPath && is_singular( 'product' )) )
$classes[] = 'current-page-ancestor';
return $classes;
}
add_filter( 'nav_menu_css_class', 'wpa83498_nav_class', 10, 2 );