Allow WordPress to Redirect to … Itself
If your WordPress admin interface (see SITE_URL
, too) lives at a domain that’s different from your actual site’s (think of your HOME_URL
), make sure to add the former to the “allowed redirect hosts.”
add_filter( 'allowed_redirect_hosts', function( $content ) {
// Different from our main site, which can be found at https://example.org.
$content[] = 'wordpress.example.org';
return array_unique( $content );
} );
If you don’t, you’ll get redirected to the admin dashboard way more often than needed, i.e., nearly every time wp_safe_redirect()
is called, like after running some kind of action, rather than stay on the settings or tools page the request originated from.
Why do this at all, you ask? Well, you might be running WordPress headlessly (and at the same time want things like inserted links to point to the main site).