Site logo

Archived topic

How to change the "login" link in the comments?

7 replies · Started by andres on September 19, 2020

Viewing posts 1–8 of 8

How to change the "login" link in the comments?
Thank

Hi there,

what change do you want to make to it?

I need to change the link for "logged in" to a user log in url instead of wp login url.

Hi,

Did you mean this link?
loginlink

You can use login_url for that. - https://developer.wordpress.org/reference/hooks/login_url/

You can try adding this PHP code.

add_filter( 'login_url', 'my_login_linkchanger');
function my_login_linkchanger( $link ) {
  $link = '?page_id=2';
  return $link;
}

Just change ?page_id=2 value to your page slug. Ex: about/ , login/ , my-account/

Let us know if it works for you.

Perfect, thanks!
What should I do to change the text "you must be logged in to post a comment"

Thanks for the link above. Just to add a solution -

I found the PHP code three comments above meant that the user did not return to the original page after login. That is really tedious for the user, and will prevent comments. So we had to accept that it had to go to the backend login.

However, with the code you linked to, I could (1) change from the Askimet wording as we wanted, and (2) add a custom registration link, while just keeping the backend login. (I customised the backend.) The code snippet is:

/* Modify the "must_log_in" string of the comment form.
 * @see http://wordpress.stackexchange.com/a/170492/26350  */
add_filter( 'comment_form_defaults', function( $fields ) {
    $fields['must_log_in'] = sprintf( 
        __( '<p class="must-log-in"><a href="%s">Login</a> to comment (or&nbsp;first&nbsp;<a href="/registration/">register</a>).</p>' 
        ),
        wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )   
    );
    return $fields;
});

Thanks!

This archived topic is closed to new replies.