Add custom links to menu targeted to primary menu
-
Hi there!
I would like to have two menus on my site: primary and secondary so i did:
add_action( 'after_setup_theme', 'register_my_menu' ); function register_my_menu() { register_nav_menu( 'primary', 'Header Menu' ); register_nav_menu( 'secondary', 'Footer Menu' ); }
And then I added some things to menus by:
/* Login button */ add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { ob_start(); wp_loginout('index.php'); $loginoutlink = ob_get_contents(); ob_end_clean(); $items .= '<li class="menu-item">'. $loginoutlink .'</li>'; return $items; } /* "Mah profile" button */ add_filter('wp_nav_menu_items', 'add_myprofile_link', 10, 2); function add_myprofile_link($items, $args) { if ( is_user_logged_in() ) { $profilelink = get_home_url() . '/zalogowany.php'; $items .= '<li class="menu-item"><a href="'.$profilelink.'"> Mah profile</a></li>'; echo $items; } else { echo ''; } }
But this code is adding those two links to both of my menus.
My question: is there a way to add those two links only to primary Header Menu?PS. I’m still working on that, later I want to minimize it to just one filter.
- The topic ‘Add custom links to menu targeted to primary menu’ is closed to new replies.