Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding custom content to Genesis custom menu
Tagged: genesis navigation bars
- This topic has 4 replies, 2 voices, and was last updated 9 years, 9 months ago by Brad Dalton.
-
AuthorPosts
-
July 31, 2014 at 6:59 pm #116505cyndimarieMember
I am currently using the Centric Pro theme. I want to use both the primary and secondary navigations, so I have re-enabled the secondary nav in functions.php.
I would like to add some custom content to the secondary nav. I need to have links for "Register/Login" to be shown if a user is not logged in, and if they are logged in I want links for "My Account/Log Out".
Here's the code I have so far and it is functioning:
add_filter( 'genesis_nav_items', 'my_loginout', 10, 2 ); add_filter( 'wp_nav_menu_items', 'my_loginout', 10, 2 ); function my_loginout($menu) { if (!is_user_logged_in()) { $outlink = 'login'; $joinlink = 'register'; $menu = $menu . $joinlink . $outlink; return $menu; } else $inlink = 'logout'; $profilelink = 'my profile'; $menu = $menu . $profilelink . $inlink; return $menu; }
The issue is that these links show up on BOTH the secondary and primary navs. I only want it on the secondary. I see the method shown here as a possible solution: http://www.billerickson.net/genesis-wordpress-nav-menu-content/ but I cannot get the extra "if" statement to function correctly.
Any help would be appreciated!
July 31, 2014 at 7:49 pm #116511Brad DaltonParticipantThere's no function for the loginout link in your code only variables without any function.
Use this http://wpsites.net/wordpress-tips/add-login-logout-link-to-any-nav-menu/
All this does nothing except output text.
$outlink = 'login'; $joinlink = 'register'; $menu = $menu . $joinlink . $outlink; return $menu; } else $inlink = 'logout'; $profilelink = 'my profile'; $menu = $menu . $profilelink . $inlink;
July 31, 2014 at 8:04 pm #116517cyndimarieMemberHi Brad
I know I can use loginout for the links. The code I posted above I had simplified to just show the text. Here's the actual code:
add_filter( 'genesis_nav_items', 'my_loginout' ); add_filter( 'wp_nav_menu_items', 'my_loginout' ); function my_loginout($menu) { if (!is_user_logged_in()) { $outlink = '<li class="custom-menu-item"><a href="/sign-in">' . __('Login') . '</a></li>'; $joinlink = '<li class="custom-menu-item"><a href="/register">' . __('Register') . '</a></li>'; $menu = $menu . $joinlink . $outlink; return $menu; } else $inlink = '<li class="custom-menu-item"><a href="'.wp_logout_url().'" >' . __('Logout') . '</a></li>'; $profilelink = '<li class="custom-menu-item"><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile') . '</a></li>'; $menu = $menu . $profilelink . $inlink; return $menu; }
I prefer to do it this way so I can customize the links further.
My real issue here is making it only show up on the secondary nav. Any idea how to do that?
August 1, 2014 at 6:08 am #116554Brad DaltonParticipantTry this wp_nav_menu_secondary_items
Source http://codex.wordpress.org/Function_Reference/wp_loginout
Or you can try http://wpsites.net/web-design/members-nav-menu-logged-in-members/
August 4, 2014 at 7:23 am #116514cyndimarieMemberHi Brad
I know I can use loginout for the links. The code I posted above I had simplified to just show the text. Here's the actual code:
// Filter wp_nav_menu() to add loginout link and register/my profile link
add_filter( 'genesis_nav_items', 'my_loginout' );
add_filter( 'wp_nav_menu_items', 'my_loginout' );
function my_loginout($menu) {
if (!is_user_logged_in()) {
$outlink = '<li class="custom-menu-item">' . __('Login') . '';
$joinlink = '<li class="custom-menu-item">' . __('Register') . '';
$menu = $menu . $joinlink . $outlink;
return $menu;
} else
$inlink = '<li class="custom-menu-item">' . __('Logout') . '';
$profilelink = '<li class="custom-menu-item">' . __('My Profile') . '';
$menu = $menu . $profilelink . $inlink;
return $menu;
}
I prefer to do it this way so I can customize the links further.
My real issue here is making it only show up on the secondary nav. Any idea how to do that?
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.