Skip to content

Instantly share code, notes, and snippets.

@tfrommen
Created August 9, 2016 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfrommen/782ae53e3869590fd4bfa562e58e75ff to your computer and use it in GitHub Desktop.
Save tfrommen/782ae53e3869590fd4bfa562e58e75ff to your computer and use it in GitHub Desktop.
Adapt the redirect target URL fallback (which is the home page by default).
<?php # -*- coding: utf-8 -*-
add_filter( 'mlp_redirect_url', function ( $url, array $match ) {
// If this is the home page, any URL is fine.
if ( is_home() || is_front_page() ) {
return $url;
}
// Prepare the HTTP language code.
$lang = str_replace( '-', '_', $match['language'] );
// Build the default home page URL for comparison.
$home_url = get_home_url( $match['site_id'] );
$home_url = trailingslashit( $home_url );
$home_url = add_query_arg( 'noredirect', $lang, $home_url );
if ( $home_url !== $url ) {
// The remote URL is not for the home page, so this is good.
return $url;
}
/*
* Build your desired target URL and return it.
*
* If you still want to redirect to a site in your network,
* but only want to manipulate the target URL,
* you might want to add the noredirect query arg to the URL.
* This is done with the following line,
* assuming you already set up the URL in $url:
*/
return add_query_arg( 'noredirect', $lang, $url );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment