Home>Support>Need to hide menu item on specific page based on session variable

Need to hide menu item on specific page based on session variable

By Seema, 8 years ago. Last reply by Alex S, 8 years ago.

Hi ,

I am very new and trying to learn web site making on my own. I am using Vantage- free theme. I need to hide menu in specific page only based on if user is logged in or not.
Adding below in style.css make the menu item hidden always but I need to make it hidden based session variable $_SESSION[‘username’]. Please help!

.page-id-32 #menu-secondary-menu #menu-item-162 {
display: none;
}

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 8 years, 3 months ago Alex S
    Hi, I Work Here

    Hi Seema,

    Just to clarify, are you trying to hide it based on a specific username or is it for any logged in user? If it’s the latter, you should use is_user_logged_in(). You should also avoid using direct session variables. You should use wp_get_current_user() instead for getting the username.

  2. 8 years, 3 months ago Alex S
    Hi, I Work Here

    Hi Seema,

    Also, just as a heads up; if you’re making direct edits to the core template files your changes will be lost on update. You should be using a child theme when making changes to theme files. Here’s a basic child theme for Vantage already set up.

  3. 8 years, 3 months ago Seema

    Hi Alex,

    I want to hide/show menu based on specific user types . example my site has only 2 types of user “customer” & “vendor”. during login validation I m storing the user types in a session variables when user logged in successfully. Please help

    Thanks,
    Seema

  4. 8 years, 3 months ago Alex S
    Hi, I Work Here

    Hi Seema,

    I personally would recommend against using session variables in the manner you’re using (as it’s unnecessary) and would instead recommend using current_user_can().

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More