Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Last active March 18, 2022 17:38
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save 2ndkauboy/390cd5e76bfd9d5492078a515bfdd1db to your computer and use it in GitHub Desktop.
Save 2ndkauboy/390cd5e76bfd9d5492078a515bfdd1db to your computer and use it in GitHub Desktop.
<?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