[Support request] How to change the “login” link in the comments?

Home Forums Support [Support request] How to change the “login” link in the comments?

Home Forums Support How to change the “login” link in the comments?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1450246
    andres

    How to change the “login” link in the comments?
    Thank

    #1450402
    David
    Staff
    Customer Support

    Hi there,

    what change do you want to make to it?

    #1451369
    andres

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

    #1451553
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

    #1452687
    andres

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

    #1452721
    Leo
    Staff
    Customer Support
    #1963538
    Simon

    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;
    });
    
    #1963568
    Leo
    Staff
    Customer Support
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.