Last active
September 21, 2017 21:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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