Extend the List of Allowed Domains for wp_safe_redirect()
What is the difference between using wp_redirect()
and wp_safe_redirect()
functions actually?
The thing is that wp_redirect()
allows to perform redirections just anywhere, but wp_safe_redirect()
by default allows only the domain specified as Site Address (URL) in Settings > General.
In this tutorial I will show you how you can add any domain as an allowed domain for wp_safe_redirect()
function using allowed_redirect_hosts
action hook.
Here is how to do that:
add_filter( 'allowed_redirect_hosts', 'rudr_extend_allowed_domains_list' );
function rudr_extend_allowed_domains_list( $hosts ){
$hosts[] = 'wordpress.com';
$hosts[] = 'misha.rudrastyh.com';
return $hosts;
}

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Hello Misha thanks for the example. I’m trying to use the login form in an external (codeigniter/CI) application. It runs in a folder *under* the wordpress site: WP URL: something.com/wp, CI URL: something.com/wp/portal. I added the whole CI URL in the CI app but not sure it does work. Should this work for a subfolder? Thanks!
This was very helpful in getting my logout redirect to go to the next link in a logout chain. Thanks for taking the time to post it!