I’m trying to figure out how to add a My Account info in nav bar or menu bar, how can i do this?
I tried various custom code but it’s not working.
Hi There,
You can try adding the following code under functions.php file locates in your child theme:
add_filter( 'wp_nav_menu_items', 'autov_add_loginout_navitem', 10, 2 );
function autov_add_loginout_navitem( $items, $args ) {
if( $args->theme_location == 'primary' ){
if(is_user_logged_in()){
$new_item = '<li class="login">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
} else {
$new_item = '<li class="login"><a href="/register/">Register</a></li>';
}
$items .= $new_item;
}
return $items;
}
how would you go about redirecting a user to a wordpress page after login for example a members page, than you so much in advance
Hi there,
It could be possible with custom development, but this would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.
Thanks for understanding. Take care!
Thats a great solution. Thanks ! But this only adds the link to the top menu. how do I add it to the FOOTER MENU too ?
Hi there,
Please use this:
add_filter( 'wp_nav_menu_items', 'autov_add_loginout_navitem', 10, 2 );
function autov_add_loginout_navitem( $items, $args ) {
if( $args->theme_location == 'primary' || $args->theme_location == 'footer' ){
if(is_user_logged_in()){
$new_item = '<li class="login">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
} else {
$new_item = '<li class="login"><a href="/register/">Register</a></li>';
}
$items .= $new_item;
}
return $items;
}
Hope this helps.