Adding Login Logout Menu Filters to Your WordPress Website

LoginPress is a WordPress login page customizer plugin that enables you to customize the login page for your WordPress site according to your requirements.

LoginPress has a cool Add-on called  Login Logout Menu.

When you activate this Add-on, you can add the login and logout menu to any place on your WordPress site. The Login Logout Menu items will change when a user Logs in or out.

This knowledgebase article will explain how to use the Login Logout Menu Filter for redirect purposes to the following places:

  1. Filter To Redirect A User To A Specific Page After Logout
  2. Filter To Redirect After Successful Login
  3. Filter To Redirect The Users To A Custom Registration Page
  4. Add/Modify Login Logout Menu Custom Username Text
  5. Filter To Redirect The User To Their Profile Page (For BuddyPress, BuddyBoss, and WooCommerce)
  6. Filter To Change The User Profile Redirect URL (For BuddyPress, BuddyBoss, and WooCommerce)

Adding filters will be done with coding, so buckle up!

Let’s get started!

1. Filter To Redirect A User To A Specific Page After Logout

If you want to redirect a user after logging out to a specific page. You have to add the given line of code into your Child's Theme file "functions.php" and save the code.

/**
 * Filter to redirect a user to a specific page after logout.
 * @return [URL] logout URL with page slug on which it will be redirected after logout
 */
add_filter( 'login_logout_menu_logout', 'loginpress_login_menu_logout_redirect' );
function loginpress_login_menu_logout_redirect() {
 return wp_logout_url( '/hello-world' );
}

Let’s see what happens when you’ll log out now:

Login Logout Menu Filters

You’ll be redirected to the “hello-world” page as given in the filter:

Login with Facebook Button

2. Filter To Redirect After Successful Login

If you want to redirect users to another specific page after login instead of the site dashboard page then you have o add the following piece of code in your Child's Theme file "functions.php" and save the code.

/**
* Filter to redirect a user to a specific page after login.
*
* @return [URL] login URL with page slug on which it will be redirected after login
*/
add_filter( 'login_logout_menu_login', 'loginpress_login_menu_login_redirect' );
function loginpress_login_menu_login_redirect() {
  return wp_login_url( '/hello-world' );
}

Note: This filter works only when a user clicks on the login button or link from the Login Logout menu otherwise user will redirect to the default website page or dashboard.

Let’s see what happens when you’ll log in from the Login Logout Menu now:

You’ll be redirected to the “hello-world” page as given in the filter:

Logout button

3. Filter To Redirect the Users to a Custom Registration Page

If you want to redirect a new website visitor to a custom registration page that you have created on your website when a new user clicks on the registration button, then you have to use the given piece of filter code in your Child's Theme file functions.php and update the file.

/**
* Filter to redirect a user to a custom register page
*
* @return [URL] custom register page URL
*/
add_filter( 'login_logout_menu_register', 'loginpress_login_menu_register_redirect' );
function loginpress_login_menu_register_redirect() {
  return home_url( '/register' );
}

Let’s see what happens when you’ll click on the registration button now:

You’ll be redirected to a custom registration page as given in the filter:

Add/Modify Login Logout Menu Custom Username Text

If you want to add a custom Username text in Login Logout Menu then you have to add the following piece of code into your Child's Theme file "functions.php" and update the file.

Note: Change the “/Welcome” to your own text. This text will be appended before the username link.

/**
* Filter to Change the user profile link text
*
* @param [String] $user_name The name of the user who is logged in
*
* @return [string] Custom String and the username
*/
add_filter( 'login_logout_menu_username', 'custom_loginpress_login_logout_menu_username' );
function custom_loginpress_login_logout_menu_username( $user_name ) {
  return 'Welcome  ' . $user_name;
}

4. Filter To Redirect The User To Their Profile Page

If you are using any of these platforms in your WordPress website (Buddyboss, BuddyPress, and WooCommerce) and want to redirect the user to their profile page instead of the WordPress dashboard. You have to insert the given code below into your Child's Theme file "functions.php" and update the file.

For BuddyPress

/**
* Filter to Change the user profile redirect URL
*
* @return [string] Custom link to user profile page
*
*/
add_filter( 'login_logout_menu_profile', 'loginpress_login_logout_menu_profile_link' );
function loginpress_login_logout_menu_profile_link( ) {
  //If BuddyPress is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
     $url = bp_core_get_user_domain( get_current_user_id() );
  }
  return $url;
}

For BuddyBoss

/**
* Filter to Change the user profile redirect URL
*
* @return [string] Custom link to user profile page
*
*/
add_filter( 'login_logout_menu_profile', 'loginpress_login_logout_menu_profile_link' );
function loginpress_login_logout_menu_profile_link( ) {
  //If BuddyBoss is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
     $url = bbp_get_user_profile_url( get_current_user_id() );
  }
  return $url;
}

For WooCommerce

/**
* Filter to Change the user profile redirect URL
*
* @return [string] Custom link to a user profile page
*
*/
add_filter( 'login_logout_menu_profile', 'loginpress_login_logout_menu_profile_link' );
function loginpress_login_logout_menu_profile_link( ) {
  //If WooCommerce is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
    $url = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) );
  }
  return $url;
}

5. Filter To Change The User Profile Redirect URL

If you are using any of these platforms in your WordPress website (Buddyboss, BuddyPress, and WooCommerce). If you want to change the user profile redirect URL [Custom URL], then you have to use the following code in your Child's Theme file "functions.php" and update your file.

For BuddyPress

/**
* Filter to Change the user redirect URL
*
* @return [string] Custom link to user profile page
*
*/
add_filter( 'login_logout_menu_username_url', 'loginpress_login_logout_menu_user_link' );
function loginpress_login_logout_menu_user_link( ) {
// If BuddyPress is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
     $url = bp_core_get_user_domain( get_current_user_id() );
  }
 return $url;
}

For BuddyBoss

/**
* Filter to Change the user redirect URL
*
* @return [string] Custom link to user profile page
*
*/
add_filter( 'login_logout_menu_username_url', 'loginpress_login_logout_menu_user_link' );
function loginpress_login_logout_menu_user_link( ) {
// If BuddyPress is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
    $url = bbp_get_user_profile_url( get_current_user_id() );
}
return $url;
}

For WooCommerce

/**
* Filter to Change the user redirect URL
*
* @return [string] Custom link to user profile page
*
*/
add_filter( 'login_logout_menu_username_url', 'loginpress_login_logout_menu_user_link' );
function loginpress_login_logout_menu_user_link( ) {
// If BuddyPress is activated then go to its User profile page.
  if ( function_exists( 'bp_core_get_user_domain' ) ) {
    $url = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) );
}
return $url;
}

That’s it. We hope you now understand how you can add the Login Logout Menu Filter to your WordPress site. 

If you have any doubts or questions related to this matter, please don’t hesitate to contact our support team.

Still stuck? How can we help?

Updated on November 30, 2022

Documentation
LoginPress Support
triangular shape yellowish icon

Frequently Asked Questions (FAQs)

These FAQs answer the most common questions about our WordPress custom login page plugin.

three shapes icon

Is LoginPress WPML Compatible?

LoginPress is fully supported with multilingual. LoginPress is also compatible with WPML Plugin, which means you can easily translate your login page with WPML plugin according to the given translation options in the WPML plugin.

Is LoginPress translation ready?

Yes, LoginPress has full translation and localization support via the LoginPress textdomain. All .mo and .po translation files should go into the languages folder in the base of the plugin.

Is coding skills needed to use LoginPress?

No, It is very easy to setup. Just plug and play. Have fun!

How to Install or Use LoginPress Pro?

Step-by-step instructions on How to Upgrade from existing Free version to Pro
1. You have installed and set up the Free version already.
2. Upload the Pro version.
3. Pro features will be enabled automatically.
4. You don’t need to set up Free version options again.
5. Setup Pro features like Google fonts, Google reCaptcha, Choose themes, etc.

Where is my license key?

License key is the Order ID which looks like in this format.
WHI150807-1234-12345
You can find it in the email Sales Receipt.

three shapes icon

If you Still have Questions?

Get In Touch