Adding the membership logout to menu

Hi there,

I have set up this plugin so that logged out users are taken to the plugins redirect (in this case, the protected accounts page). As the user is not logged in they first have to log
This works great, but the problem I am having is that when they leave the website, the only way to logout is to return to their (protected) account and click the logout link.
Is there a way to make it easier for a logged in user to log out without having to return to the accounts page?
I want to avoid them having to use the default wp login/logout page.

Thanks to you and wpmu for your help with this plugin.

Cheers
Colinz

  • Michael Bourne
    • Site Builder, Child of Zeus

    This will give a Login/Logout link in your nav, just place in your functions.php:

    // Log In / Out link in Nav
    // =============================================================================
    
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) {         ob_start();         wp_loginout('index.php');         $loginoutlink = ob_get_contents();         ob_end_clean();         $items .= '<li>'. $loginoutlink .'</li>';     return $items; }
  • colinz
    • WPMU DEV Initiate

    Thanks Anastasia and Michael.
    Unfortantely, the WP solution takes you through the WP login/out rather than keeping it front end (Membership pro login/out). Redirecting the login/out results in being unable to logout.

    I tried the solution you kindly passed me Michael, but I white screened!

    Thanks anyhow.

    Cheers
    Colinz

  • Sajid
    • DEV MAN’s Sidekick

    Hi @colinz

    Hope you are doing god today :slight_smile:

    Try using this code and let me know the results.

    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
    function add_loginout_link( $items, $args ) {
        if ( is_user_logged_in() ) {
            $items .= '<li>  <a href="'. wp_logout_url( get_permalink() ) .'">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() ) {
            $items .= '<li><a href="'.  wp_login_url( get_permalink() ) .'">Log In</a></li>';
        }
        return $items;
    }

    This will redirect user on current page after login/logout. If you want to add it in a primary navigation menu only then let me know and I will give you an updated code.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • colinz
    • WPMU DEV Initiate

    Hi,

    Big thanks to you guys for offering a number of solutions. It turned out that the easiest (with regards to keeping the process away from the WP login/logout pages) was to use the shortcode. A copout I know but ... !
    Cheers
    Colinz

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.