Skip to content
  • RSS Feed
  • Korean
WordPress Information Center
  • Home
  • Inquiry and partnership

Home » Advanced WordPress » How to redirect to previous page after login with the Ultimate Member plugin in WordPress

How to redirect to previous page after login with the Ultimate Member plugin in WordPress

December 24, 2017 by WordCracker

Ultimate Member is a WordPress profile and membership plugin which has been active in more than 80k sites.

It's a free plugin but it's possible to extend the features by using (premium) extensions.

You can specify the redirection URL after registration or login under Ultimate Member > User Roles.

How to redirect to previous page after login with the Ultimate Member plugin in WordPress 1

You can choose one from the following options for Action to be taken after login:

  • Redirect to profile
  • Redirect to URL
  • Refresh active page
  • Redirect to WordPress Admin

Among them, if you choose the Refresh active page option, users will be redirected to the Account page intead of previous page (or referring page) after login.

If you want to redirect users to the previous page (or current active page before login attempt), please add the following code to your theme's function file (i.e. functions.php). Of course, it's strongly recommended to create a child theme.

// Add Login and Logout menu items to menu whose menu name (theme_location) is 'primary'
// Redirects to current page after login/logout

add_filter( 'wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2 );

function wti_loginout_menu_link( $items, $args ) {
if ($args->theme_location == 'primary') {
if (is_user_logged_in()) {
$items .= '<li class="right"><a href="'. wp_logout_url( get_permalink() ) .'">Logout</a></li>'; // For logout
} else {
$items .= '<li class="right"><a href="'. wp_login_url(get_permalink()) .'">Login</a></li>'; // For login
}
}
return $items;
}

Please change the value of theme_location depending on your theme's navigation. It may be generally 'primary', 'main' or similar. For Avada, you may use "menu-main-nav."

Categories Advanced WordPress
Font Awesome Icons Not Displaying Issue in Avada
How to change 'Theme By: Theme Horse' in the Attitude/Interface WordPress themes
WordCracker Profile

WordCracker

Professional Korean-English translator. WordPress enthusiast. Admin of the Naver Café 「WordPress Users Community」 | LinkedIn | Threads

Fast WordPress Web Hosting

Popular WordPress Themes

Top-selling WP Theme

  • Partnership
  • Privacy Policy
  • Contact
  • 한국어
Copyright(C) Designed with GeneratePress