How to hide buttons for logged in users in wordrpess

How to Hide Buttons In WordPress For Logged In Users?

To hide any button in your wordpress website for logged in users you need to add a css class called “.logged-in” into your theme additional css which is located in the customize page.

wordpress hide button if logged in
Hide button for logged in users in wordpress

The class “logged-in” is already idenified on wordpress as “only for logged in users” and it can be used in various ways to hide any element from your website.

Here are some quick examples on hiding a button for logged in/ logged out users:

Hide a button for all users (logged in and logged out)

.button-class
display: none;
}

Hide a button only for logged in users and show for logged out

.logged-in .button-class
display: none;
}

Hide a button for logged out users and show for logged in

#this will hide it for all users
.button-class
display: none;
}
# this will show it for logged in users only
.logged-in .button-class{
display: block;
}

Hide menu item if user is logged in

You can also use “.logged-in” class to hide items from your website menu only if user is logged in. All what you need to do is to add it before the code of the item you are targeting. Here is an example

.logged-in .your-item-class{
display: none;
}

How to hide a menu items for logged in users by using a plugin

If you don’t want to use css codes you can install a wordpress plugin called If Menu – Visibility control for Menu Items. it will help you to hide or show any item on your menu when a user is logged in.

After you install it, you go to your menu from appearance → menus

wordpress hide button if logged in

Then you can hide or show each item when a user is logged in by doing these steps:

  1. Click on the item that you want to hide from your menu, then click on “enable visibility” button.
  2. Change the first option from “show” to “hide”
  3. Click on “is Administrator” and change it to “is logged in”
wordpress hide button if logged in

If Menu plugin also can be used to hide menu item for other rules. For example you can hide/show items for your menu if the user is an vendor or editor, author, subscriber… etc

Another way of hiding buttons for logged in users is by using php codes, and for that you can check this article from wordpress developers resources

Any Thoughts?

if you’ve got any thoughts on how to hide elements in wordpress for logged in users , or any questions, feel free to share them in the comments down below. i do my best to reply to everyone!.

And if you enjoyed this article, it’d be great if you could consider sharing it on social media, or adding a link to it from your website or blog.

Thanks for reading..

People also search for

wordpress if user logged in
wordpress button class
wordpress hide menu
wordpress menu buttons
if user logged in wordpress
wordpress button classes
hide button
wordpress if user is logged in
hide menu wordpress
wordpress is user logged in
wordpress user logged in

2 Comments

    • You can use this code

      #this will hide the element for all users
      .class
      display: none;
      }
      # this will show the element for logged in users only
      .logged-in .class{
      display: block;
      }

Leave a Reply

Your email address will not be published. Required fields are marked *