Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Add conditions to a link?

Featured Replies

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 :-)

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.