Add External Link to OnePage Section Menu
-
Hello,
I’m using a theme built-in menu, that navigates over sections, and I’ve added an li on header.php menu builder to add a link to another page (so I won’t use only one page, the second page is a custom link to a product).<nav id="site-navigation" class="main-navigation" role="navigation" itemscope itemtype="https://schema.org/SiteNavigationElement"> <ul> <?php if( ! get_theme_mod( 'business_one_page_ed_home_link' ) ){ if( is_front_page() ){ ?> <li class = "<?php echo esc_attr( 'current-menu-item', 'business-one-page' ); ?>"><a href="<?php echo esc_url( home_url( '#home' ) ); ?>"><?php echo esc_html( $home_link_label ); ?></a></li> <?php }else{ ?> <li><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php echo esc_html( $home_link_label ); ?></a></li> <?php } } foreach( $enabled_sections as $section ){ if( $section['menu_text'] ){ ?> <li><a href="<?php echo esc_url( home_url( '#' . esc_attr( $section['id'] ) ) ); ?>"><?php echo esc_html( $section['menu_text'] );?></a></li> <?php } } ?> --mycustomlink <li id ="shopitem"><a href="https://site/product/custport1/">shop</a></li> </ul> </nav>
Everything works ok, I can navigate between my second page and the main page, but I cannot highlight the menu item of second page when I’m in.
I’ve tried with
function special_nav_class($classes, $item){ if ( is_product() && $item->title == "shop" ) { $classes[] = 'current-menu-item'; } if ( is_checkout() && $item->title == "shop" ) { $classes[] = 'current-menu-item'; } return $classes; } add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
but it doesn’t apply the filter.
Is there a way to do it?
Thank you for your helpHugo
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Add External Link to OnePage Section Menu’ is closed to new replies.