I am wanting to place a dynamic Login/Logout link in my main menu. When user is logged out the Login link would take them to a custom CRED Login page for login and the form would redirect the user after login, so not sure if I need the redirection code used below. When the user logs out they should be redirected to a specified page.
Have gone over the steps from the other post many times as well as quite a bit of research on Google. Not able to get the link to show up. I have provide my latest iteration of the code I am putting at the end of my functions.php file. Would value your assistance. I am using the Toolset Starter Theme and it, as well as all Toolset plugins, are up to date as of this post.
//Add login/logout link to naviagation menu
function add_login_out_item_to_menu( $items, $args ){
if( is_admin() || $args->theme_location != 'header-menu' )
return $items;
$redirect = ( is_home() ) ? false : get_permalink();
if( is_user_logged_in( ) )
$link = '<a href="' . wp_logout_url( $redirect ) . '" title="' . __( 'Logout' ) .'"><i class="fa glyphicon fa-lock"></i>' . __( 'logout' ) . '</a>';
else $link = '<a href="<em><u>hidden link</u></em>" title="' . __( 'Login' ) .'"><i class="fa glyphicon fa-lock"></i>' . __( 'login' ) . '</a>';
return $items.= '<li id="log-in-out-link" class="menu-item menu-type-link">'. $link . '</li>';
}
add_filter( 'wp_nav_menu_items', 'add_login_out_item_to_menu', 50, 2 );
//Redirect to Specific Page after user is Logged-in:
add_action(
'wp_login',
create_function(
'',
'wp_redirect("'.get_permalink(36).'");exit();'
)
);
//Redirect to Specific Page after user is Logged-out:
add_action(
'wp_logout',
create_function(
'',
'wp_redirect("'.get_permalink(2).'");exit();'
)
);
ADDTIONAL INFO:
Still working on this and after reading other support threads I thought I should clarify once again that I am using the Toolset Starter Theme and my main menu is added to the header using the latest building methods via Toolset Layouts. Not sure if this adds a level of complexity that the code my not be taking into consideration. Again would value your assistance.
Hi Minesh... Gave the provided code a try and it does not appear to work. Tried it as is as well as replaced "primary" with the Toolset Starter Theme "header-menu". Please advise?
Hello Minesh... Thank you for confirming that this method does not in fact work with the Toolset Starter Theme. As for the plugin I have used that and yes it is quite simple and affective, just not the amount of flexibility I was looking for.
During all this I did come to another approach on my own that happens to be totally a Toolset centric approach. Here is a link to the thread with my solution. It is fairly complete but there were a couple typos that I hope are not confusing to others. The edit functionality timed out before I got a chance to update it.
I really wish Toolset had someone who could approach your product from this perspective and provide purpose centric solutions that would help users like myself who are coming from the professional business side of things not the development site building services side. Toolset is a powerful business tool, I hope it continues to grow as such.
Thanks for all you do,
Dave
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.