Skip to content

Instantly share code, notes, and snippets.

@tott
Created November 14, 2013 14:14
Show Gist options
  • Select an option

  • Save tott/7467467 to your computer and use it in GitHub Desktop.

Select an option

Save tott/7467467 to your computer and use it in GitHub Desktop.
Enforce domain mapping mapped domain for all front-end urls ran through esc_url()
add_filter( 'clean_url', 'sav_force_mapped_url' );
function sav_force_mapped_url( $url ) {
if ( ! is_admin() ) {
if ( function_exists( 'get_original_url' ) && strpos( '/wp-admin', $url ) === false ) {
$original = preg_replace( '#^https?://#', '', get_original_url('') );
$new = preg_replace( '#^https?://#', '', site_url() );
$url = str_ireplace( $original, $new, $url );
}
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment