Add LearnDash Custom URL Login and Logout Custom Redirects

LearnDash has a filter named learndash_login_url which is a shortcode and allows manipulation of the login and logout pages when used with the $action parameter.

LearnDash Login Shortcode

Place the LearnDash shortcode where you want the login/logout button to appear. Below the shortcode also uses custom labels for both login and logout states.

[learndash_login login_label="Member Login" logout_label="Member Logout"]

LearnDash Login Redirect

Use the learndash_login_url filter as below to change the login and logout URLs. This is added to your themes functions.php file.

add_filter( 'learndash_login_url', 'ld_learndash_login_logout_url', 10, 3 );
// Set custom login and logout URLs in LearnDash
function ld_learndash_login_logout_url( $url, $action, $atts ) {
if ( $action === 'logout' ) {
// Go to your home page on logout
$url = wp_logout_url( home_url( '/' ) );
}

if ( $action === 'login' ) {
// Go to your custom login page
$url = home_url( '/member-login/' );
}

return $url;
}

So if the $action is logout I have set the destination URL to be the home page and if the $action is login the user is redirected to a custom user login page to authenticate.

Categorised

Leave the first comment