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

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me