• Resolved humanfiles

    (@humanfiles)


    I’m trying to change the “Logged in as {name}. Log out?” text that appears above the comments box, but I’m not having much luck.

    I do know the code that would enable this would be dropped in functions.php, probably using ‘comment_form_logged_in’, but I’m not savvy enough to write it myself.

    I don’t want the text before the name to be part of the link, just the name.

    I plan on floating “Log Out” to the right side of the comment box, but I know I can do any styling like that with css.

    Any ideas? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Try this:

    add_filter('comment_form_logged_in', function( $logged_in_as, $commenter, $user_identity) {
      return sprintf(
                '<p class="logged-in-as">%s</p>',
                sprintf(
                    /* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */
                    __( 'Logged in as <a href="%1$s" aria-label="%2$s">%3$s</a>. <a class="log-out-link" href="%4$s">Log out?</a>' ),
                    get_edit_user_link(),
                    /* translators: %s: User name. */
                    esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
                    $user_identity,
                    /** This filter is documented in wp-includes/link-template.php */
                    wp_logout_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ), get_the_ID() ) )
                )
            );
    }, 10, 3 );

    The sprintf() calls are copied from comment_form() source code and were slightly modified. I left the translator notes for reference, but the altered strings will not be translated.

    Thread Starter humanfiles

    (@humanfiles)

    That worked perfectly. Thank you!

    I searched everywhere for that solution. Hopefully this helps someone else.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change “Logged in as {name}” Text’ is closed to new replies.