Sky Login Redirect Shortcode

Below, you’ll find a detailed guide on how to add the Sky Login Redirect Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Sky Login Redirect Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Sky Login Redirect Plugin and the shortcodes it provides:

Plugin Icon
Sky Login Redirect

"Sky Login Redirect is a user-friendly WordPress plugin designed to customize and manage the redirection process after users log in or log out of your website."

★★★★☆ (22) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [login-logout]

Sky Login Redirect [login-logout] Shortcode

The Sky-login-redirect shortcode is a smart tool that automatically displays a login or logout link based on the user’s status. It checks if the user is logged in. If true, it shows a logout link, else, a login link is displayed. This shortcode makes user navigation seamless and intuitive.

Shortcode: [login-logout]

Examples and Usage

Basic example – The shortcode for the sky-login-redirect plugin can be used to display a login or logout button, depending on the user’s status.

[login-logout /]

Advanced examples – Although the given function for the shortcode does not include parameters or attributes, you can modify the function to include them. Here’s an example:

function Slr_Login_Logout_shortcode($atts)
{
    $atts = shortcode_atts( array(
        'login_text' => 'Login',
        'logout_text' => 'Logout',
    ), $atts, 'login-logout' );
    
    if ( is_user_logged_in() ) {
        return '' . esc_html__( $atts['logout_text'], 'sky-login-redirect' ) . '';
    } else {
        return '';
    }
}

With this modification, you can now customize the text displayed on the login and logout buttons. Here’s an example:

[login-logout login_text="Sign in" logout_text="Sign out" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [login-logout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'login-logout', __NAMESPACE__ . '\\Slr_Login_Logout_shortcode' );

Shortcode PHP function:

function Slr_Login_Logout_shortcode()
    {
        
        if ( is_user_logged_in() ) {
            // user is logged in, therefore display the logout link
            // If you want to redirect the user to the same page after logout,
            // then use this line below instead
            return '<a class="logout-btn slr-lilo-shortcode" href="' . esc_url( wp_logout_url() ) . '">' . esc_html__( 'Logout', 'sky-login-redirect' ) . '</a>';
        } else {
            // user is logged out, therefore display the login link
            return '<a class="login-btn slr-lilo-shortcode" href="' . esc_url( wp_login_url() ) . '">' . esc_html__( 'Login', 'sky-login-redirect' ) . '</a>';
        }
    
    }

Code file location:

sky-login-redirect/sky-login-redirect/sky-login-redirect.php

Conclusion

Now that you’ve learned how to embed the Sky Login Redirect Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *