I need to change the link for “logged in” to a user log in url instead of wp login url.
I have checked /wp-includes/comment-template.php and that’s what I found on line 2217
/** This filter is documented in wp-includes/link-template.php */
'must_log_in' => '<p class="must-log-in">' . sprintf(
/* translators: %s: login URL */
__( 'You must be <a href="https://wordpress.stackexchange.com/questions/258398/%s">logged in</a> to post a comment.' ),
wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) )
) . '</p>',
If this is the right place to customize the “logged in” link, how should be the code with a new login page url example: yourdomain.com/my-account ??
1 Answer
To change the login link only in this template, replace the wp_login_url()
function call with your login link:
'must_log_in' => '<p class="must-log-in">' . sprintf(
/* translators: %s: login URL */
__( 'You must be <a href="https://wordpress.stackexchange.com/questions/258398/%s">logged in</a> to post a comment.' ),
"https://yourdomain.com/my-account"
) . '</p>',
If you want to generally redirect users to another url if they need to log in, it is better to use the filter login_url
:
function wpse_258398_login_url ( $login_url, $redirect, $force_reauth ) {
return "https://yourdomain.com/my-account";
}
add_filter( 'login_url', 'wpse_258398_login_url', 10, 3);
Be aware though, this will affect all redirects to login. Even when you are redirected to login for the admin backend.