The get_the_author_login() WordPress PHP function retrieves the login name of the author of the current post.
Usage
echo get_the_author_login();
_If the author’s login is “john_doe”, this will output “johndoe”.
Parameters
This function has no parameters.
More information
See WordPress Developer Resources: get_the_author_login()
Examples
Display author’s login in a post
Display the author’s login name in a single post template (single.php)
// Inside the WordPress loop echo 'Author: ' . get_the_author_login();
Display author’s login with a custom prefix
Add a custom prefix before the author’s login name
// Inside the WordPress loop echo 'Written by: ' . get_the_author_login();
Use author’s login in a CSS class
Include the author’s login name in a CSS class for unique styling
// Inside the WordPress loop echo '<div class="post-author-' . get_the_author_login() . '">'; // Post content here echo '</div>';
Display author’s login in a link
Create a link to the author’s archive page with their login name as the link text
// Inside the WordPress loop echo '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '">' . get_the_author_login() . '</a>';
Show author’s login only for a specific user role
Display the author’s login name only if the author has a specific user role, e.g. “editor”
// Inside the WordPress loop if ( in_array( 'editor', (array) get_the_author_meta( 'roles' ) ) ) { echo 'Editor: ' . get_the_author_login(); }