s2Member Pro on WP: change membership login mysite.com/wp-login.php to mysite.com/login without any issues?

Hello s2Member Community,

With s2Member Pro, can I change the membership login mysite.com/wp-login.php to mysite.com/login without any issues?

If it does cause problems, can I create a different login portal page and how I redirect and have all functionality?

From a security perspective it makes sense to change the /wp-login.php to minimize risks.

Running PHP 7.1X, mySQL, updated WordPress. Thank you for your time!

It’s fine to make that change. I have done it on almost all my sites.

Hi Tim, thank you for responding. What method do you use to change the /wp-login.php? I know there’s a number of apps that’ll do it but they won’t work if the plugin has the wp-login.php hard coded.

I am a strong advocate of using WP’s built-in methods. These are intended to ensure that everything still works. So I use WP’s login_url filter.

Hi Tim,

Do you have a working script that I could use to safely perform the redirect? Below is what I am considering trying but concerned on breaking the site.

Not sure if this older code could potentially perform the redirect function in the wp-includes/general-template.php:

add_filter( ‘login_url’, ‘my_login_page’, 10, 2 );
function my_login_page( $login_url, $redirect ) { if(stristr($redirect,“admin”)){ wp_safe_redirect(’/site_url/404.php’); }else{ return str_replace(“wp-login.php”,“custom_url_string”,$login_url); } } add_action( ‘login_form’, ‘replace_login_submit_form’,1); function replace_login_submit_form() { $your_content = ob_get_contents(); $your_content = str_replace(“wp-login.php”,“custom_url_string”,$your_content); ob_get_clean(); echo $your_content; }

Or

add_filter( ‘login_url’, ‘my_login_page’, 10, 3 );
function my_login_page( $login_url, $redirect, $force_reauth ) {
$login_page = home_url( ‘/my-login-page/’ );
$login_url = add_query_arg( ‘redirect_to’, $redirect, $login_page );
return $login_url;
}

Do I need to specify > ‘login_url’ and > $login_url as mysite.com?

Also do I add one of the scripts above above or below my current script shown below?

function wp_logout_url($redirect = ‘’) {
$args = array( ‘action’ => ‘logout’ );
if ( !empty($redirect) ) {
$args[‘redirect_to’] = urlencode( $redirect );
}

$logout_url = add_query_arg($args, site_url(‘wp-login.php’, ‘login’));
$logout_url = wp_nonce_url( $logout_url, ‘log-out’ );

I am nervous of making a mistake. Thank you again for your time.

You are making it more complicated than you need. This is what I do:

function kts_login_page( $login_url ) {
    return home_url( '/my-login-page/' );
}
add_filter( 'login_url', 'kts_login_page' );
1 Like

Hi Tim,

Thanks for the snippet! I placed it on the top of the wp-includes/general-template.php and wasn’t able to get the ‘/my-login-page/’ to work properly. That’s why I asked if I need to add it above or below the equivalent login code (below is logout):

function wp_logout_url($redirect = '') {
$args = array( 'action' => 'logout' );
if ( !empty($redirect) ) {
$args['redirect_to'] = urlencode( $redirect );
}
$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
$logout_url = wp_nonce_url( $logout_url, 'log-out' );

Thanks again for your time!

Whoa! You have put it in entirely the wrong place. You should NEVER touch core files. You’re lucky it just didn’t work. That’s the easiest way to break things.

Just add what I gave you to your active theme’s functions.php file.

Thank you Tim. Got it sorted. Have a nice day.

1 Like