WordPress.org

Ready to get started?Download WordPress

Forums

BAW Login/Logout menu
[resolved] [Plugin: BAW Login Logout Menu] Suggestion: hide login/out links when irrelevent (4 posts)

  1. Gabe462
    Member
    Posted 1 year ago #

    I want to to put my login and log out links in different places in my menu. For example, when logged out, a "login" menu is displayed. When logged in, an "account" menu item is displayed, and "log out" is a submenu item of that.

    What I'm suggesting, is an option to hide the login or logout menu item based on whichever is unnecessary.

    http://wordpress.org/extend/plugins/baw-login-logout-menu/

  2. Julio Potier
    Member
    Plugin Author

    Posted 1 year ago #

    You can do this by adding CSS classes in your menu entry. Then, based on whichever is unnecessary, you add a CSS inline style with /STYLE tag and add a my-class{ display:none; }
    What do you think abut that

  3. Gabe462
    Member
    Posted 1 year ago #

    I worry about trusting generic ID's like "#menu-item-667". But I went for it this time :)

    thanks

  4. professor99
    Member
    Posted 1 year ago #

    An idea along this line is to put the following code into your functions.php file.

    <?php
    /*
     * Suppress/show items if user not logged in.
     *
     * class login: Display if user logged in.
     * class logout: Display if user logged out
     */
    
    add_filter(  'wp_head' , 'loginout_css' );
    
    function loginout_css() {
    	if (is_user_logged_in()){
    ?>
    		<style type="text/css" media="screen">
    			.logout{
    				display:none;
    			}
    		</style>
    	<?php } else { ?>
    		<style type="text/css" media="screen">
    			.login{
    				display:none;
    			}
    		</style>
    <?php
    	}
     }
    ?>

    Then just add the login/logout class to any html tag you want displayed/suppressed for logged in/out users.

    In the case of menu items first proceed to the menu admin screen. Select screen options (window top right) and make sure the 'CSS Classes' checkbox item is checked.

    Then on the relevant menu bar click on the down arrow on it's right to display it's options. Then add 'login' or 'logout' to the 'CSS Classes (optional)' item.

    Works a dream!

    Cheers
    TheProfessor

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.