Global 404 for WPMU or WP Multi Sites

By Glenn Ansley  |  June 22nd, 2010  |  Published in WordPress

I quickly drafted the following code in response to this tweet:

I really really really really want a MU universal 404 file.less than a minute ago via TweetDeck

function global_404() {
	if ( is_404() ){
		wp_redirect( 'http://site.com/global404' );
		die();
	}
}
add_action( 'template_redirect', 'global_404' );

If placed inside a plugin that is activated on every site in your network, the above code will do the following:

  1. Determine that the user looked for a page that didn’t exist.
  2. Redirect to a URL of your choice, regardless of the site that they are currently viewing.

Leave a Response