I have a taxonomy page that lists all the sub-categories. I want to link directly to the sub-category position of that page from the main navigation menu.
I set up a menu with the main category (Products), and then added all the sub-categories as children of that menu.
By default, the sub-menu items link to the individual sub-category pages. I don't want this to happen, so I filter the sub-menu items and replace the URL (href value) with an anchor link.
My code is as follows:
function my_product_anchor_links( $atts, $item, $args ) {
if ($item->type == 'taxonomy' && $item->object == 'myproductcategory' ) {
$url = $atts['href'];
$new_url = rtrim($url,'/');
$new_url = str_replace('myproducts/','myproducts/#',$new_url);
$atts['data-href'] = $new_url;
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'my_product_anchor_links', 10, 3 );
This code successfully changes sub-category URLs from:
http:://example.com/myproducts/sub-category/
to:
http://ift.tt/1FyMjLg
However, when the site is rendered in the browser, the URL appears in the menu as: http://ift.tt/1vCSFt1
Why (or where) is WordPress stripping out the hashed portion of the URL in the menu?
Aucun commentaire:
Enregistrer un commentaire