Do you have a problem with spambot registrations or have custom fields added to your BuddyPress Registration page? Maybe users are getting to the /wp-login.php?action=register page instead of your /register/ page? Here’s a snippet I came up with to redirect the first to the second.
The Code
Put this snippet in your active theme’s functions.php file or in your own plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function force_my_own_registration_page() {
// by Clifford Paulick, 2012-08-09, tested with WP 3.4.1 and BP 1.6
$turnon = 1; // 1 = yes, 0 = no
$currenturl = strtolower($_SERVER["HTTP_HOST"]) . strtolower($_SERVER["REQUEST_URI"]);
$findme = 'wp-login.php?action=register';
$pos = strpos($currenturl, $findme);
if ( $turnon == 1 && $pos !== false) {
wp_safe_redirect( '/?p=8' , 301 );
}
}
add_action('init', 'force_my_own_registration_page');
|
Code references and variations
- In the code above, my /register/ page is page ID 8. This way, if I change /register/ to /signup/, the code still works. Edit the snippet for your purposes.
- To add additional URLs to find and redirect, you can add more variables and if statements, just copying the logic. If you create separate functions instead, make sure to name them differently (i.e. not duplicate the function name).
- I added a $turnon variable so you can deactivate the functionality without having to comment out the code. It’s not really better or worse, just an option that’s there for you.
- The wp_safe_redirect function
- The wp_redirect function (for redirecting outside the referring domain; make sure to add the exit command)
Featured Plugin - WordPress Pop-Up Chat Plugin
Screenshots
WordPress’ wp-login screen has a link to the /wp-login.php?action=register page.
Clicking to the /wp-login.php?action=register page (without my snippet) will result in the following registration page.
We want users to go to our BuddyPress registration page, as chosen in the BuddyPress settings.
With my snippet above, if they get to the /wp-login.php?action=register URL, they’ll be redirected to our specified BuddyPress Registration page (where all the plugins and BuddyPress profile fields are).
Featured Plugin - WordPress Newsletter Plugin
Related plugins and articles
You may want to use this code snippet together with these plugins and articles:




that is so awesome hey just wondering any testing with prior versions of buddypress (we haven’t yet upgraded to 1.6)
Hi Ben. Glad you like it. To be honest, it’s not BuddyPress dependent. It’s a simple redirect: “if you find THIS string anywhere in the full URL, redirect to THAT other internal page”. However, I mentioned BuddyPress because it’s most common to have your own dedicated Registration page when using BP. Does that help?
yeah thanks! sorry I’m a bit slow with the coding stuff.