I have http://example.com/admin.php

There I check whether the user is admin or not. If not, I send the user to the wp-login page like this:


I expect redirect back for admin.php but WordPress always sends me to wp-admin control panel.

After researching, I found that when the destination host is not in filter allowed_redirect_hosts, WP just redirects the user to wp-admin.

How can I add more hosts to the filter?

If I put this example from the WP Codex in functions.php, it stops working.

add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
function my_allowed_redirect_hosts($content){
    $content[] = 'blog.example.com';
    $content[] = 'codex.example.com';
    // wrong: $content[] = 'http://codex.example.com';
    return $content;
  • It looks like that should work. When you say "it stops working", what do you mean? Users get redirected to wp-admin, or you get error messages, or the site goes blank, or...? Also, if you can post the code you used -- not the stuff from the Codex, but the actual code that you tried in functions.php -- that might help. – Pat J Jul 16 '13 at 0:40
  • I tested the filter and successfully added www.google.com to the 'safe' list. That filter works. The problem is elsewhere. Something else in code not posted is going on that is causing the problem. – s_ha_dum Jul 16 '13 at 4:44
  • Thank you two.I added the code just replacing the strings for "google.com", to the functions.php. Just it stop working and the page goes blank, like a php error. Maybe i must add the code in the theme's function.php? – chipi92 Jul 16 '13 at 9:57

Finally it works! What I was doing wrong is putting the code in the WP functions.php file, and not in my custom theme functions.php file.

Thanks all!

  • Glad you got it working. For future reference: All code that you are adding belongs in either your theme files (usually wp-content/[themename]/functions.php) or a plugin (usually in wp-content/plugins/[...]). The general rule of thumb is don't hack core. – Pat J Jul 16 '13 at 16:27

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.