Here's some sample code on redirecting on login and logout. It's incredible... I've found multiple answers on this function in both the WordPress codex and Stack Exchange. MOST DO NOT WORK. Which is typical inconsistent and misinforming WordPress information on the web.
function my_login_redirect( $redirect_to, $request, $user ) {
$redirect_to = '/items/'; return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
function redirect_after_logout() {
if (!current_user_can('manage_options')) {
$url = '/';
} else {
$url = 'wp-login.php?loggedout=true';
}
$redirect_url = home_url( $url );
wp_safe_redirect( $redirect_url );
exit;
}
add_action('wp_logout', 'redirect_after_logout');
Dev & Tech Notes
San Diego | Los Angeles | Big Bear | USA
Terms & Conditions ©2005-2024 TJohns.co
Terms & Conditions ©2005-2024 TJohns.co
Articles in this Category
- Add Menus to Wordpress
- Changing Admin Password in WordPress Database
- Hide Admin Bar on Front End
- Hook References
- Inserting New Admin into WordPress Database
- List of WordPress Template Tags
- Reading from & Writing to the WordPress Database
- Some WordPress Basic Variables
- Some WordPress Conditionals
- Using Arrays in WordPress Database
- Using Custom Field in WordPress for Conditional Statement
- WordPress Login & Logout Redirect
- WordPress Logout Menu Link
Top Left Text cha
Web & App Development
WordPress Login & Logout Redirect
- Details
- Written by Timothy Johns
- Category: WordPress
- Hits: 3812
Comments