Skip to content

Instantly share code, notes, and snippets.

@jamesmorrison
Last active September 21, 2017 21:29
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 jamesmorrison/5f8a3108b2a773cd07db430b73992e9d to your computer and use it in GitHub Desktop.
Save jamesmorrison/5f8a3108b2a773cd07db430b73992e9d to your computer and use it in GitHub Desktop.
Adding this to your theme will redirect any requests for wp-signup.php (triggered upon visiting a multisite network address that doesn't exist) to the network home URL along with some GA parameters
<?php
/**
* @package Header for WP Signup
* @author James Morrison
* @link https://gist.github.com/jamesmorrison/5f8a3108b2a773cd07db430b73992e9d/edit
*
* This file is called by the WP core /wp-signup.php file; we can force a redirect from here
*
* Whilst you can do this from the NOBLOGREDIRECT constant, the advantage of using this header
* file is that you can capture the path that triggered the call to signup; as seen in the example
* below, this uses Google Analytics parameters to help track where the requests came from without
* the need to setup infrastructure level redirects.
*
* Additionally, NOBLOGREDIRECT has a nasty habit of messing about with 404 pages - in some cases
* it treats these as an invalid network site and triggers the redirect instead of showing the 404 page
*
**/
wp_redirect(
esc_url_raw(
add_query_arg( [
'utm_source' => isset( $_GET[ 'new' ] ) ? esc_attr( $_GET[ 'new' ] ) : '',
'utm_medium' => 'referral',
'utm_campaign' => 'no-blog-redirect'
], network_home_url() )
),
301 );
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment