Below, you’ll find a detailed guide on how to add the Login Logout Menu Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Login Logout Menu Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Login Logout Menu Plugin and the shortcodes it provides:
"Login Logout Menu is a dynamic WordPress plugin that seamlessly integrates login and logout options in your site's menu. User-friendly and convenient, it simplifies user navigation."
- [login_logout_menu__login_link]
- [login_logout_menu__logout_link]
- [login_logout_menu__profile_link]
- [login_logout_menu__register_link]
- [login_logout_menu__username_link]
- [login_logout_menu__reset_pass_link]
- [login_logout_menu__login_logout_link]
Login Logout Menu [login_logout_menu__login_link] Shortcode
The Login Logout Menu shortcode serves to display a login link. If a user is not logged in, it returns a ‘Log in’ link based on the current page URL.
Shortcode: [login_logout_menu__login_link]
Parameters
Here is a list of all possible login_logout_menu__login_link shortcode parameters and attributes:
login_url
– sets the URL to redirect users after loginlogin_text
– defines the text displayed on the login linklogin_logout_class
– assigns a CSS class to the login link for styling
Examples and Usage
Basic example – A simple usage of the login_logout_menu__login_link shortcode. This will display a login link that redirects to the current page after login.
[login_logout_menu__login_link /]
Advanced examples
Customizing the login link text and adding a CSS class. In this example, the login link text is set to “Sign In” and the CSS class “custom-login-class” is added to the link element for styling purposes.
[login_logout_menu__login_link login_text="Sign In" login_logout_class="custom-login-class" /]
Customizing the login redirect URL. Here, the user will be redirected to the homepage after login instead of the current page.
[login_logout_menu__login_link login_url="https://www.yourwebsite.com/" /]
Combining all parameters. This example demonstrates the usage of all available parameters. The login link text is set to “Sign In”, a custom CSS class is added, and the user is redirected to a custom URL after login.
[login_logout_menu__login_link login_text="Sign In" login_logout_class="custom-login-class" login_url="https://www.yourwebsite.com/" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__login_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__login_link', array( $this, 'login_logout_menu__login_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__login_link_callback( $atts ) {
if ( is_user_logged_in() )
return;
//Current Page URL
$item_redirect = site_url( $_SERVER['REQUEST_URI'] ) ;
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'login_url' => $item_redirect,
'login_text' => __( 'Log in', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
//If user is logged in
if ( ! is_user_logged_in() ) {
return '<a href="' . wp_login_url( $args['login_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . ' " title="' . esc_attr( $args['login_text'] ) . '">' . esc_html( $args['login_text'] ) . '</a>';
}
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__logout_link] Shortcode
The ‘login_logout_menu__logout_link’ shortcode is a feature of the Login Logout Menu plugin. It allows the display of a logout link when a user is logged in. The link redirects to the current page after logout. It also allows customization of the logout text and the class of the logout link for styling purposes.
Shortcode: [login_logout_menu__logout_link]
Parameters
Here is a list of all possible login_logout_menu__logout_link shortcode parameters and attributes:
logout_url
– The URL where the user will be redirected after logging out.logout_text
– The text that appears on the logout link.login_logout_class
– The CSS class applied to the logout link.
Examples and Usage
Basic example – The basic usage of the shortcode displays a logout link with the default settings. The link redirects to the current page after logout, and the link text reads ‘Log out’.
[login_logout_menu__logout_link /]
Advanced examples
Customizing the logout link text – This example demonstrates how you can change the text of the logout link by using the ‘logout_text’ attribute.
[login_logout_menu__logout_link logout_text="Sign Out" /]
Redirecting to a specific page after logout – In this example, the ‘logout_url’ attribute is used to redirect the user to a specific page (e.g., the home page) after logout.
[login_logout_menu__logout_link logout_url="https://yourwebsite.com/" /]
Applying a custom CSS class to the logout link – This example shows how you can apply a custom CSS class to the logout link using the ‘login_logout_class’ attribute. This can be useful for styling the link according to your website’s design.
[login_logout_menu__logout_link login_logout_class="my_custom_class" /]
Combining multiple attributes – This final example demonstrates how you can combine multiple attributes to customize the logout link’s text, redirection URL, and CSS class.
[login_logout_menu__logout_link logout_text="Sign Out" logout_url="https://yourwebsite.com/" login_logout_class="my_custom_class" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__logout_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__logout_link', array( $this, 'login_logout_menu__logout_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__logout_link_callback( $atts ) {
if ( ! is_user_logged_in() )
return;
//Current Page URL
$item_redirect = site_url( $_SERVER['REQUEST_URI'] ) ;
// Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'logout_url' => $item_redirect,
'logout_text' => __( 'Log out', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
//If user is logged in
return '<a href="' . wp_logout_url( $args['logout_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . ' " title="' . esc_attr( $args['logout_text'] ) . '">' . esc_html( $args['logout_text'] ) . '</a>';
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__profile_link] Shortcode
The Login Logout Menu shortcode enables users to add a profile link to their site’s menu. It checks if a user is logged in and displays an ‘Edit Profile’ link accordingly. The shortcode incorporates various attributes such as URL, edit_text, and login_logout_class. The URL redirects to the profile page, edit_text displays ‘Edit Profile’, and login_logout_class adds a CSS class to the link.
Shortcode: [login_logout_menu__profile_link]
Parameters
Here is a list of all possible login_logout_menu__profile_link shortcode parameters and attributes:
url
– The link to the user’s profile page.edit_text
– The text displayed for the profile link.login_logout_class
– The CSS class assigned to the profile link.
Examples and Usage
Basic example – The following shortcode will generate a profile link for the logged-in user with the default “Edit Profile” text and the default class “login_logout_class”.
[login_logout_menu__profile_link /]
Advanced Examples
Customizing the text and class of the profile link. In this example, we are changing the text to “Update Your Profile” and the class to “custom_class”.
[login_logout_menu__profile_link edit_text="Update Your Profile" login_logout_class="custom_class" /]
Overriding the default profile URL. This example shows how to use a custom URL for the profile link. The custom URL is “http://example.com/my-profile”.
[login_logout_menu__profile_link url="http://example.com/my-profile" /]
Combining multiple parameters. This example combines all the above parameters to create a customized profile link with a custom URL, text, and class.
[login_logout_menu__profile_link url="http://example.com/my-profile" edit_text="Update Your Profile" login_logout_class="custom_class" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__profile_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__profile_link', array( $this, 'login_logout_menu__profile_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__profile_link_callback( $atts ){
if ( ! is_user_logged_in() )
return ;
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'url' => esc_url( apply_filters( 'login_logout_menu_profile', Login_Logout_Menu::login_logout_menu_profile_link() ) ),
'edit_text' => __( 'Edit Profile', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
return '<a href="' . esc_url( $args['url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . '" title="' . esc_attr( $args['edit_text'] ) . '">' . esc_html( $args['edit_text'] ) . '</a>';
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__register_link] Shortcode
The ‘login_logout_menu__register_link’ shortcode from the Login-Logout-Menu plugin is designed to generate a registration link. It checks if a user is logged in. If not, it retrieves the current page URL and sets it as the redirect URL after registration. It also includes customizable attributes such as the registration URL, text, and class. This shortcode returns a link that directs the user to the registration page when clicked.
Shortcode: [login_logout_menu__register_link]
Parameters
Here is a list of all possible login_logout_menu__register_link shortcode parameters and attributes:
register_url
– The URL where the user will be redirected after registration.register_text
– The text displayed for the registration link.login_logout_class
– The CSS class assigned to the registration link.
Examples and Usage
Basic example – Displaying a simple registration link with default values
[login_logout_menu__register_link /]
In this basic example, the shortcode will generate a registration link. If a user is not logged in, a ‘Register’ link will be displayed, which will redirect the user to the same page after registration. The link will have the default class ‘login_logout_class’.
Advanced examples
Customizing the registration link with different parameters
[login_logout_menu__register_link register_url="https://yourwebsite.com/custom-page" register_text="Sign Up" login_logout_class="custom_class" /]
In this advanced example, the shortcode is used with three parameters. The ‘register_url’ parameter is used to set a custom redirection URL after registration. The ‘register_text’ parameter is used to customize the text of the registration link. The ‘login_logout_class’ parameter is used to add a custom CSS class to the registration link for styling purposes.
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__register_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__register_link', array( $this, 'login_logout_menu__register_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__register_link_callback( $atts ) {
if ( is_user_logged_in() )
return;
//Current Page URL
$item_redirect = site_url( $_SERVER['REQUEST_URI'] ) ;
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'register_url' => $item_redirect,
'register_text' => __( 'Register', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
//If user is not logged in
return '<a href="' . wp_registration_url( $args['register_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . '">' . esc_html( $args['register_text'] ) . '</a>';
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__username_link] Shortcode
The Login Logout Menu shortcode is a user-friendly tool that displays the username of the logged-in user. It also provides a link to the user’s profile. This shortcode checks if a user is logged in and fetches the username. It then applies filters to the username and creates a URL to the user’s profile. The username and the profile link are then displayed in a customizable class.
Shortcode: [login_logout_menu__username_link]
Parameters
Here is a list of all possible login_logout_menu__username_link shortcode parameters and attributes:
url
– sets the destination URL when the username is clicked.username
– displays the current logged-in user’s name.login_logout_class
– assigns a CSS class to the username link for styling purposes.
Examples and Usage
Basic example – A simple usage of the ‘login_logout_menu__username_link’ shortcode without any additional parameters.
[login_logout_menu__username_link /]
Advanced examples
Adding a custom URL to the ‘login_logout_menu__username_link’ shortcode. This will redirect the user to the specified URL after clicking on the username.
[login_logout_menu__username_link url="https://yourwebsite.com/custom-url" /]
Using the shortcode with a custom username and a custom CSS class. The ‘username’ parameter will change the display name of the logged-in user, and the ‘login_logout_class’ parameter will add a custom CSS class to the link.
[login_logout_menu__username_link username="Custom Username" login_logout_class="custom-class" /]
Combining all parameters in one shortcode. This example includes a custom URL, a custom username, and a custom CSS class.
[login_logout_menu__username_link url="https://yourwebsite.com/custom-url" username="Custom Username" login_logout_class="custom-class" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__username_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__username_link', array( $this, 'login_logout_menu__username_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__username_link_callback( $atts ){
if ( ! is_user_logged_in() )
return ;
$current_user = wp_get_current_user();
$username = apply_filters( 'login_logout_menu_username', $current_user->display_name );
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'url' => esc_url( apply_filters( 'login_logout_menu_username_url', Login_Logout_Menu::login_logout_menu_profile_link() ) ),
'username' => $username,
'login_logout_class' => 'login_logout_class',
), $atts );
return '<a href="' . esc_url( $args['url'] ) . '" class="'.esc_attr( $args['login_logout_class'] ) . '" title="' . esc_attr( $args['username'] ) . '">' . esc_html( $args['username'] ) . '</a>';
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__reset_pass_link] Shortcode
The Login Logout Menu shortcode enables users to reset their passwords. It checks if a user is logged in and if not, it generates a reset password link.
Shortcode: [login_logout_menu__reset_pass_link]
Parameters
Here is a list of all possible login_logout_menu__reset_pass_link shortcode parameters and attributes:
lostpassword_url
– defines the redirect URL after resetting the passwordlostpassword_text
– sets the text for the reset password linklogin_logout_class
– assigns a CSS class to the reset password link
Examples and Usage
Basic example – A simple usage of the shortcode to generate a reset password link with default parameters.
[login_logout_menu__reset_pass_link /]
Advanced examples
Changing the text of the reset password link. In this example, the ‘lostpassword_text’ attribute is used to change the display text of the reset password link to ‘Forgot Password’.
[login_logout_menu__reset_pass_link lostpassword_text="Forgot Password" /]
Adding a custom CSS class to the reset password link. In this example, the ‘login_logout_class’ attribute is used to apply a custom CSS class ‘my_custom_class’ to the reset password link.
[login_logout_menu__reset_pass_link login_logout_class="my_custom_class" /]
Combining multiple attributes. In this example, both the ‘lostpassword_text’ and ‘login_logout_class’ attributes are used together to change the display text and apply a custom CSS class to the reset password link.
[login_logout_menu__reset_pass_link lostpassword_text="Forgot Password" login_logout_class="my_custom_class" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__reset_pass_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__reset_pass_link', array( $this, 'login_logout_menu__reset_pass_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__reset_pass_link_callback( $atts ) {
if ( is_user_logged_in() )
return;
//Current Page URL
$item_redirect = site_url( $_SERVER['REQUEST_URI'] ) ;
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'lostpassword_url' => $item_redirect,
'lostpassword_text' => __( 'Reset Password', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
return '<a href="' . wp_lostpassword_url( $args['lostpassword_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . '" title="' . esc_attr( $args['lostpassword_text'] ) . '">' . esc_html( $args['lostpassword_text'] ) . '</a>';
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Login Logout Menu [login_logout_menu__login_logout_link] Shortcode
The Login-Logout-Menu shortcode is a dynamic tool for managing user access. It displays a link that changes based on the user’s login status. This shortcode creates a login or logout link, depending on whether the user is logged in or not. It uses the current page URL as the default redirect after login or logout. The text for the login and logout links can be customized.
Shortcode: [login_logout_menu__login_logout_link]
Parameters
Here is a list of all possible login_logout_menu__login_logout_link shortcode parameters and attributes:
login_url
– defines the URL where user will be redirected after logging inlogout_url
– sets the URL where user will be sent after logging outlogin_text
– sets the text displayed for the login linklogout_text
– sets the text displayed for the logout linklogin_logout_class
– sets the CSS class for the login/logout link
Examples and Usage
Basic example – A simple usage of the shortcode to create a login/logout link with default parameters.
[login_logout_menu__login_logout_link /]
Advanced examples
Customizing the shortcode to specify the login and logout URLs, as well as custom text for the login and logout links. This allows for a more personalized user experience.
[login_logout_menu__login_logout_link login_url="https://yourwebsite.com/login" logout_url="https://yourwebsite.com/logout" login_text="Sign In" logout_text="Sign Out" /]
Adding a custom CSS class to the login/logout link. This allows for more control over the appearance of the link through CSS styling.
[login_logout_menu__login_logout_link login_logout_class="my_custom_class" /]
Combining all of the above for a fully customized login/logout link. This example demonstrates the flexibility of the shortcode and how it can be tailored to fit a variety of needs.
[login_logout_menu__login_logout_link login_url="https://yourwebsite.com/login" logout_url="https://yourwebsite.com/logout" login_text="Sign In" logout_text="Sign Out" login_logout_class="my_custom_class" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [login_logout_menu__login_logout_link]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'login_logout_menu__login_logout_link', array( $this, 'login_logout_menu__login_logout_link_callback' ) );
Shortcode PHP function:
function login_logout_menu__login_logout_link_callback( $atts ) {
//Current Page URL
$item_redirect = site_url( $_SERVER['REQUEST_URI'] ) ;
//Default args adding in the shortcode as shortcode attributes
$args = shortcode_atts( array(
'login_url' => $item_redirect,
'logout_url' => $item_redirect,
'login_text' => __( 'Log in', 'login-logout-menu' ),
'logout_text' => __( 'Log out', 'login-logout-menu' ),
'login_logout_class' => 'login_logout_class',
), $atts );
//If user is logged in
if ( is_user_logged_in() ) {
return '<a href="' . wp_logout_url( $args['logout_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . ' "title="' . esc_attr( $args['logout_text'] ) . '">' . esc_html( $args['logout_text'] ) . '</a>';
} else {
return '<a href="' . wp_login_url( $args['login_url'] ) . '" class="' . esc_attr( $args['login_logout_class'] ) . '"title="' . esc_attr( $args['login_text'] ) . '">' . esc_html( $args['login_text'] ) . '</a>';
}
}
Code file location:
login-logout-menu/login-logout-menu/classes/shortcodes.php
Conclusion
Now that you’ve learned how to embed the Login Logout Menu Plugin shortcodes, 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.
Leave a Reply