Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
/*
* Multisite Main-Site Redirect
* @package MultisiteMainSiteRedirect
* @author Bernhard Kau
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: Multisite Main-Site Redirect
* Plugin URI: https://kau-boys.de
* Description: Redirect the main site of a multisite to another domain or sub-site
* Version: 0.1
* Author: Bernhard Kau
* Author URI: https://kau-boys.de
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
function multisite_mainsite_redirect() {
if ( is_main_site() && ! is_admin() && 'wp-login.php' != $GLOBALS['pagenow'] && ! defined( 'WP_CLI' ) ) {
wp_redirect( 'http://example.com/' );
exit();
}
}
add_action( 'init', 'multisite_mainsite_redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment