Forums

Hide 'register' menu when logged in! (21 posts)

  1. cellydy
    Member
    Posted 2 years ago #

    I want logged in members to not see the 'register' page (on menu)

    How can I hide certain pages from certain users?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    We are going to need more information before we can help.

    What are you referring to? What menu? In a theme? A widget?

    Site url and better description may help

  3. cellydy
    Member
    Posted 2 years ago #

    Well this is what I mean:

    A user can register and then login. When a user is logged in I want him not to see the 'register' option in the menu as he is already registered (and logged in).

    Is there a way to make 'registered' users not see certain pages?

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    yep, that's pretty much what you said the first time.

    And then I asked you for a link to your site so that we can help.
    I don't know what menu you are referring to.

    Is it something in your theme? Is it a widget?

    For instance, at the bottom of my theme, I have it set up so that if you are NOT logged in it says
    Log In | Register

    If you ARE logged in it says
    Log Out | Site Admin

  5. xdesi
    Member
    Posted 2 years ago #

    Yeah just use the wordpress conditional is_user_logged_in along with a php if statement

    For example:

    <?php
    if(is_user_logged_in()){
    //Then user is logged in do what you want here for logged in users
    else{
    //User is not logged in do what you want here for non-logged in users
    }
    ?>

    You can use this logic for the menu item and preventing a page from showing I guess.

  6. cellydy
    Member
    Posted 2 years ago #

    Ill try xdesi's proposal cause that sounds just like what I need :)

  7. cellydy
    Member
    Posted 2 years ago #

    site is: http://www.wowgoldadvisor.com

    How Can I configure:

    if(is_user_logged_in()){
    //Then user is logged in do what you want here for logged in users
    else{
    //User is not logged in do what you want here for non-logged in users
    }
    ?>

    so that in the main menu of my site under 'User' It hides 'Register' when user is logged in and 'Profile' when not logged in?

    The menu displays pages.

  8. xdesi
    Member
    Posted 2 years ago #

    What's the code for your top menu then just something like:

    wp_list_pages(); ?

  9. cellydy
    Member
    Posted 2 years ago #

    wp_list_pages yep

  10. xdesi
    Member
    Posted 2 years ago #

    Hm one possible way, replace your wp_list_pages(); with this:

    $mypages = wp_list_pages('echo=0');
    if(is_user_logged_in()){
    	$reglink = '<li class="page_item page-item-79"><a href="http://wowgoldadvisor.com/?page_id=79" title="Register">Register</a></li>';
    	$mypages = str_replace($reglink,'',$mypages);
    }
    echo $mypages;

    Note: If you had arguments in your wp_list_pages function add them to the end of echo=0 with an amperstand e.g wp_list_pages('echo=0&title_li=')

    All the code is doing is removing the register link from the pages if the user is logged in.

    I'm sure RVoodoo will know a better way as i'm not too sure on how to manipulate wp_list_pages() to the greatest of effects!

  11. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I'm sure RVoodoo will know a better way as i'm not too sure on how to manipulate wp_list_pages() to the greatest of effects!

    nono...I was learning from you here!

    Unfortunately...I usually scan the forums here to try and help folks from work, while taking breaks. Our internet has filters...and sites like the OPs (anything to do with gaming usually) get blocked....so I can't look at the site to provide specific feedback

  12. xdesi
    Member
    Posted 2 years ago #

    nono...I was learning from you here!

    Unfortunately...I usually scan the forums here to try and help folks from work, while taking breaks. Our internet has filters...and sites like the OPs (anything to do with gaming usually) get blocked....so I can't look at the site to provide specific feedback

    Fair enough, my method should do the trick, it's just that it's a bit manual, i'm sure there's a dozen ways to do it as is the case with anything concerning WP!

  13. cellydy
    Member
    Posted 2 years ago #

    Unfortunately I'm not to pro at all this :)

    I found w-_list_pages in the header.php and thats where i replaced the data.

    It didnt work (It completely deleted the menu :( )

    Is that the wrong place or does it not work?

  14. cellydy
    Member
    Posted 2 years ago #

    This is what I found

    <?php
    if (get_option('woo_nav') == 'true' )
    wp_list_categories('sort_column=menu_order&depth=3&title_li=&exclude=');
    else
    wp_list_pages('sort_column=menu_order&depth=3&title_li=&exclude=');
    ?>

    I selected list by Pages in the admin panel.

    How Do I edit that for it to work?

    Cheers

  15. xdesi
    Member
    Posted 2 years ago #

    Try this: (replace above with this):

    <?php
    if (get_option('woo_nav') == 'true' )
    wp_list_categories('sort_column=menu_order&depth=3&title_li=&exclude=');
    else{
    $mypages = wp_list_pages('echo=0&sort_column=menu_order&depth=3&title_li=&exclude=');
    if(is_user_logged_in()){
    	$reglink = '<li class="page_item page-item-79"><a href="http://wowgoldadvisor.com/?page_id=79" title="Register">Register</a>';
    	$mypages = str_replace($reglink,'',$mypages);
    }
    echo $mypages;
    }
    ?>
  16. cellydy
    Member
    Posted 2 years ago #

    Worked!

    Could you also hide the 'login' link (as they are already logged in :P)

    I tried but I didnt manage for it to work :S

    Cheers for all your help btw :)

  17. xdesi
    Member
    Posted 2 years ago #

    No probs, try:

    <?php
    if (get_option('woo_nav') == 'true' )
    	wp_list_categories('sort_column=menu_order&depth=3&title_li=&exclude=');
    else{
    	$mypages = wp_list_pages('echo=0&sort_column=menu_order&depth=3&title_li=&exclude=');
    	if(is_user_logged_in()){
    		$reglink = '<li class="page_item page-item-79"><a href="http://wowgoldadvisor.com/?page_id=79" title="Register">Register</a>';
    		$loginlink = '<li class="page_item page-item-24"><a href="http://wowgoldadvisor.com/?page_id=24" title="Login">Login</a></li>';
    		$mypages = str_replace($reglink,'',$mypages);
    		$mypages = str_replace($loginlink,'',$mypages);
    	}
    	echo $mypages;
    }
    ?>

    Would you also want the "Profile" link to only show if people are logged in?

  18. cellydy
    Member
    Posted 2 years ago #

    fantastic!

    And finally! (:P)

    If I want to hide 'Profile' Link from NON logged on people? (so it just displays Login + Register)

    Could you please help out this last time?

    Thanks soooooo much for your help :)

  19. xdesi
    Member
    Posted 2 years ago #

    Try this it's a simpler option:

    <?php
    if (get_option('woo_nav') == 'true' )
    	wp_list_categories('sort_column=menu_order&depth=3&title_li=&exclude=');
    else{
    	if(is_user_logged_in()){
    		wp_list_pages('sort_column=menu_order&depth=3&title_li=&exclude=79,24');
    	}
    	else{
    		wp_list_pages('sort_column=menu_order&depth=3&title_li=&exclude=85');
    	}
    }
    ?>
  20. cellydy
    Member
    Posted 2 years ago #

    Thanks for all your Help!

    Cheers

  21. bdollproject
    Member
    Posted 2 years ago #

    Thank you for this, this is exactly what I needed, thank you so much! Much appreciation!

Topic Closed

This topic has been closed to new replies.

About this Topic