Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Resolved] Switch login/logout depending on session status

Simple Membership Plugin › Forums › Simple Membership Plugin › Switch login/logout depending on session status

  • This topic has 2 replies, 2 voices, and was last updated 3 weeks, 1 day ago by juwe81.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • October 27, 2026 at 5:51 am #32415
    juwe81
    Participant

    Hello,
    I’ve implemented all the features I need from the plugin into my website and it’s working like charm.

    I only have one functionality I haven’t been able to find in the documentation and this forum. I want to add an item that switches functionality depending on session status. If the user is a guest -> show Login link. If user is a member, show Logout link.

    I’d be comfortable with coding to check session status but I haven’t found any clues on this.

    Thanks!

    October 28, 2026 at 7:23 am #32432
    admin
    Keymaster

    Hi, Glad to hear everything else is working well.

    The easiest option is the mini login shortcode. It shows a “Login Here” link to guests and a “Logout” link (along with the username and a profile link) to logged-in members:

    [swpm_mini_login]

    The following page explains how to use it in a sidebar, header or footer:
    https://simple-membership-plugin.com/adding-mini-login-widget-sidebar-header-footer/

    If you’d rather code it yourself (for example, as a menu item), you can use the following function to check the session status. It returns true when a member is logged in:

    SwpmMemberUtils::is_member_logged_in()

    Here is an example snippet that adds a Login/Logout item to the end of a menu. Add it to your child theme’s functions.php file (or use a code snippets plugin), and change “primary” to your menu’s theme location:

    
    add_filter( 'wp_nav_menu_items', 'my_swpm_login_logout_menu_item', 10, 2 );
    function my_swpm_login_logout_menu_item( $items, $args ) {
        if ( $args->theme_location !== 'primary' || ! class_exists( 'SwpmMemberUtils' ) ) {
            return $items;
        }
        if ( SwpmMemberUtils::is_member_logged_in() ) {
            $url   = home_url( '/?swpm-logout=true' );
            $label = 'Logout';
        } else {
            $url   = SwpmSettings::get_instance()->get_value( 'login-page-url' );
            $label = 'Login';
        }
        $items .= '<li class="menu-item"><a href="' . esc_url( $url ) . '">' . esc_html( $label ) . '</a></li>';
        return $items;
    }
    

    Note: If you use any page caching on your site, make sure it is bypassed for logged-in members. Otherwise visitors may see the wrong link. The following page has more details:
    https://simple-membership-plugin.com/understanding-the-impact-of-caching-on-membership-sites/

    Let me know if you have any questions.

    October 28, 2026 at 8:07 pm #32434
    juwe81
    Participant

    Thank you so much! The PHP snippet worked like a charm!

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy