Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created February 9, 2023 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ideadude/6493d4becfae4e52b08af66339f3ef30 to your computer and use it in GitHub Desktop.
Save ideadude/6493d4becfae4e52b08af66339f3ef30 to your computer and use it in GitHub Desktop.
Redirect all WordPress users to a very specific page on login.
<?php
/**
* Redirect all users to a very specific page on login.
* This should work no matter what login form/etc you are using.
* If it doesn't work, maybe the 999 priority needs to be higher.
* If you want to respect the redirect_to param or earlier callbacks
* that overwrite it, uncomment the section at the top of the function.
*
* You can add this code to your site using the Code Snippets plugin or by
* placing the code into a custom plugin or your theme's functions.php.
*/
function my_login_redirect( $redirect_to ) {
// If you'd like to honor previously set redirects, uncomment this section.
/*
if ( ! empty( $redirect_to ) ) {
return $redirect_to;
}
*/
// Set your redirect.
$redirect_to = home_url(); // Use home_url( '/my-page-slug/' ); to use a specific slug/URL on the site.
return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment