The comment_form_logged_in WordPress PHP filter modifies the ‘logged in’ message for the comment form displayed on the front end.
Usage
add_filter('comment_form_logged_in', 'your_custom_function', 10, 3); function your_custom_function($args_logged_in, $commenter, $user_identity) { // your custom code here return $args_logged_in; }
Parameters
$args_logged_in
(string): The HTML for the ‘logged in as [user]’ message, the Edit profile link, and the Log out link.$commenter
(array): An array containing the comment author’s username, email, and URL.$user_identity
(string): If the commenter is a registered user, the display name, blank otherwise.
More information
See WordPress Developer Resources: comment_form_logged_in
Examples
Change the logged-in message
This example changes the default ‘logged in as [user]’ message to ‘Welcome, [user]!’.
add_filter('comment_form_logged_in', 'change_logged_in_message', 10, 3); function change_logged_in_message($args_logged_in, $commenter, $user_identity) { $args_logged_in = 'Welcome, <strong>' . esc_html($user_identity) . '</strong>!'; return $args_logged_in; }
Add a custom message after the logged-in message
This example adds a custom message after the default ‘logged in as [user]’ message.
add_filter('comment_form_logged_in', 'add_custom_message', 10, 3); function add_custom_message($args_logged_in, $commenter, $user_identity) { $custom_message = '<p>Thanks for being a part of our community!</p>'; return $args_logged_in . $custom_message; }
Remove the ‘Edit profile’ link
This example removes the ‘Edit profile’ link from the logged-in message.
add_filter('comment_form_logged_in', 'remove_edit_profile_link', 10, 3); function remove_edit_profile_link($args_logged_in, $commenter, $user_identity) { return preg_replace('/<a.*?>(Edit your profile.*?)<\/a>/', '', $args_logged_in); }
Add a ‘View profile’ link
This example adds a ‘View profile’ link next to the ‘Edit profile’ link in the logged-in message.
add_filter('comment_form_logged_in', 'add_view_profile_link', 10, 3); function add_view_profile_link($args_logged_in, $commenter, $user_identity) { $user = wp_get_current_user(); $view_profile_url = get_author_posts_url($user->ID); $view_profile_link = '<a href="' . esc_url($view_profile_url) . '">View profile</a>'; return $args_logged_in . ' | ' . $view_profile_link; }
Change the ‘Log out’ link text
This example changes the ‘Log out’ link text to ‘Sign out’.
add_filter('comment_form_logged_in', 'change_logout_link_text', 10, 3); function change_logout_link_text($args_logged_in, $commenter, $user_identity) { return str_replace('Log out', 'Sign out', $args_logged_in); }