How to Extend the List of Allowed Domains for wp_safe_redirect()

It is one of my shortest tutorials ever. But I decided to publish it anyway because I didn’t find any information about it anywhere.

WordPress home_url() in general settings
WordPress home URL in Settings > General. By default wp_safe_redirect() allows to redirect only to this domain excluding subdomains.
add_filter( 'allowed_redirect_hosts', 'misha_extend_allowed_domains_list' );
function misha_extend_allowed_domains_list( $hosts ){
	$hosts[] = 'wordpress.com';
	$hosts[] = 'misha.rudrastyh.com';
	return $hosts;
});

That’s all 😁

Read also

Misha Rudrastyh

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

Follow me on Twitter