2

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="%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 ??

2
  • I posted an answer, but I am not sure if it is specific enough for your use case. If you explain a little more in detail what you are actually trying to achieve, a more helpful answer can be given.
    – JHoffmann
    Mar 1, 2017 at 9:32
  • Yes, this is exactly what I need. I edited my code as yours and it is working properly now. I also tried your second code and it works well, but I don't want admins to be redirected to the customized login page, so I deleted it again and kept the first one. Thank You Mar 1, 2017 at 10:53

1 Answer 1

0

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="%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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.