October 8, 201412 yr Hello.... I am hoping someone maybe able to help me as I am getting in such a muddle. I am working with a theme that has a login section. Basically, it has a "login" link in the menu bar, which when clicked on, opens a slide down login section. The URL is added via the menu within the WP dashboard by adding span tags and putting the URL as #topReveal, it looks like this:- <a href="#topReveal"><span class="mmLogin">Login</span></a> Unfortunately, when you login, it doesn't show you are logged in. I wanted it to change to a logout link but I think that's far too complex for me to do alone. So my thoughts where to change is so, if the person is logged in, it just says "logged in" instead of "login". I have searched high and low but just got frustrated trying to find something. I found this:- function jc_nav_menu_items( $items, $args ) { $items .= '<li id="menu-item-logout" class="menu-item menu-item-logout"><a href="'.wp_logout_url('/').'">'.__('Logout').'</a></li>'; return $items; } add_filter('wp_nav_menu_items','jc_nav_menu_items', 10, 2); So I thought perhaps I could hard code the menu item in, rather than using the dashboard like this:- function jc_nav_menu_items( $items, $args ) { $items .= '<a href="#topReveal"><span class="mmLogin">Login</span></a>'; return $items; } add_filter('wp_nav_menu_items','jc_nav_menu_items', 10, 2); But how can I add conditional statements to the "Login" text - is this even possible? Any help would be greatly appreciated :-)
October 8, 201412 yr That might do the job, adding conditional statement, detecting if the user is logged in: function jc_nav_menu_items( $items, $args ) { if ( !is_user_logged_in()){ // IF USER IS NOT LOGGED IN $items .= '<a href="#topReveal"><span class="mmLogin">Login</span></a>'; } else { // IF USER IS LOGGED IN ...your logged out menu item ... } return $items; } add_filter('wp_nav_menu_items','jc_nav_menu_items', 10, 2);
Create an account or sign in to comment