0

I want to change the "logged in as " link that displays in the reply comments form if logged in. The link is leading to wordpress profile in the backend, which it shouldn't. I want it to just a paragraph instead of an a tag . However i can't fint anywhere to change it, as there is not customizable template as far as i know.

Thanks.

0

We could try to rebuild the HTML through the comment_form_logged_in filter, where the HTML is constructed by default as:

'<p class="logged-in-as">' . sprintf(
/* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
     __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a 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,
     wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) )
 ) . '</p>'

But since it's rather complex and we might loose the translations, when rebuilding it, we might try to replace it (once) instead with e.g.:

add_filter( 'comment_form_logged_in', function( $html, $commenter, $user_identity )
{
  return preg_replace( '#<a href="[^"]*" aria-label="[^"]*">([^<]*)</a>#', '$1', $html, 1);
}, 10, 3 );

or with a DomDocument approach. See e.g. here.

Note that if the translation string changes in core, this might need adjustments!

  • Thank you! That fixed. Just as you seem to be knowledged: do you have a snippet to check if there is a breadcrumb trail shown or not? – Magnus Pilegaard Aug 11 '17 at 12:35
  • Glad to hear it helped. Maybe better served as a new question. @MagnusPilegaard – birgire Aug 11 '17 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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