Documentation

Print This page

Login Logout Menu Filters

Filter To Redirect A User To A Specific Page After Logout

If you want to redirect a user after log out to a specific page that you have created on your website. Simply you have to add the given piece 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' );
}

 Filter To Add Redirect After Successful Login

If you want to redirect your website user to another specific page that you have created on your website instead of a site dashboard page then you have to 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 click on the login button or link from the Login Logout menu otherwise user will redirect to the default website page or dashboard.

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 click 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' );
}

Add/Modify Login Logout Menu Custom Username Text

If you want to change the Username text in Login Logout Menu on your WordPress website then you have to insert the following piece of code into your Child’s Theme file “functions.php” and update the file.

/**
* Filter to Change the user profile link text
*
* @param [String] $user_name The name of the user which 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;
}

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 you want to redirect the user to their profile page instead of the WordPress dashboard, then 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 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;
}

Filter To Change The User Profile Redirect URL

If you are using any of these platforms in your WordPress website (Buddyboss, BuddyPress, and WooCommerce) and you want to change the user profile redirect URL [Custom URL] then you have to use the following piece of 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;
}