WordPress.org

Ready to get started?Download WordPress

Forums

How to Hide Custom Menu when logged out (5 posts)

  1. rixtertrader
    Member
    Posted 1 year ago #

    I've found several discussing this topic in some form or fashion, but could not find a solution that didn't involve using a plug-in that does not work with 3.4.2 WP.

    So if there isn't a plug-in tested yet for this version of WP that can help, perhaps an easy PHP tweak?

    If a tweak, please let me know in baby-talk as I'm not a native PHP programmer (C# my venue). This WP setup thing is all new to me.

    I created a CUSTOM MENU called FORUMS that points to a URL created by bbPress that lists my available forums.

    I'm can't find any way to set this particular page to PROTECTED, so I imagine that's why the menu remains even when logged out. My other menu items (pages) hide when logged out. But my CUSTOM menu does not, although clicking it will get you to a dead page when logged out. It just looks bad to have a dead menu showing when not logged in.

    How do I go about hiding this custom menu when logged out?

    Thanks in advance.

  2. justingreerbbi
    Member
    Posted 1 year ago #

    Have you looked into modifying the theme header and adding is_user_logged_in() function
    Here?

  3. rixtertrader
    Member
    Posted 1 year ago #

    Hello justingreerbbi,

    Thanks for your comment.

    I've not seen that suggested or done that at this point.

    Again, I'm 'brand new' to all this so getting around PHP files and knowing exactly where to place/remove/edit things is a bit tricky without exact directions.

    However, perhaps I can figure this out now that you have mentioned this function.

    Thanks.

    I'll post my results shortly. :)

  4. rixtertrader
    Member
    Posted 1 year ago #

    I'm using the Twenty-ten/bbPress theme and in its header.php I found this line that appears related to the menu.

    <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>

    At this point, until I learn more about PHP, I have to assume this holds all the menu items in this 'array'. So if I wrap this code inside the function is_user_logged_in(), then I suppose it won't display the array items if not logged in, etc.

    But in my case, there is ONE menu item, not the whole menu, that needs to go away. I need the LOGOUT menu item to remain.

    Anyway, I tested this out and sure enough when I go to my site the whole menu is not there because I'm not logged in. Can't log in without the menu, so I've got to figure out how to filter out a single menu item from the whole menu.

    While I attempt to figure this out, if anyone happens to pass by here and can give me a quick hint as to where to go, I would appreciate.

    Love this stuff. A whole new world. lol. :)

    Thanks again.

  5. rixtertrader
    Member
    Posted 1 year ago #

    Okay, running into a brick wall. :-b

    It looks like what I need to do is have TWO menus defined. I've created MEMBERSHIP and LOGIN as my two menus.

    Only one can be the Primary menu for the Twenty-ten theme.

    So what I guess I need to do is to programically change the Primary Menu for when LOGGED IN or LOGGED OUT.

    Can I do this? So far I'm not sure.

    I figure this all have to be done BEFORE the code in header.php is reached...

    <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>)

    ...

    Anyone? Anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic