I am creating a plugin to redirect all sign in attempts to a dedicated page rather than using the builting wordpress page
so i created this hook action for the admin_init with the highest priority over other callbacks

add_action( 'admin_init', 'redirect_callback', 1)

the callback function will then make sure the user is not signed in already to make the redirect

function redirect_callback() {
    if ( ! is_user_logged_in() ) {
      wp_redirect( /* my link */ );

and of course the is_user_logged_in() needs this dependency


visiting this link: url/wp-admin still doesn't redirect anywhere, it still pulls up the wordpress press sign in page.
anyone can help ?


this line did the task perfectly

add_filter( 'login_url', function(){return /* the custom URL */;});

here is the explanation:(valid for wordpress 5.4.1)
by the time admin_init fires, it's too late already.
once url/wp-admin is visited, index.php launches first
then requires admin.php (line 10)
then the file will execute 94. auth_redirect();
before 170. do_action( 'admin_init' );

auth_redirect() core function uses wp_login_url()
which in its turn uses login_url, as indicated in the wordpress documentation plage. we can apply a filter to it with any URL we like.

| improve this answer | |

So I add an action to call the function:

// Redirect anyone from the wp-login screen to the custom distributor login


Then I create a function to direct to custom url:

function custom_login(){  
   global $pagenow;  
   if( 'wp-login.php' == $pagenow && $_GET['action']!="logout") {  
| improve this answer | |
  • 1
    thank you for your contribution but there is an "exit;" missing after the redirect, because wp_redirect doesnt exit automatically. – Amine Jun 1 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.