The get_the_author_lastname() WordPress PHP function retrieves the last name of the author of the current post.
Usage
$author_lastname = get_the_author_lastname(); echo "Author's last name: " . $author_lastname;
Parameters
This function has no parameters.
More information
See WordPress Developer Resources: get_the_author_lastname()
Examples
Displaying the author’s last name with the post title
This example will display the author’s last name along with the post title.
if ( have_posts() ) { while ( have_posts() ) { the_post(); $author_lastname = get_the_author_lastname(); echo "<h2>" . get_the_title() . " by " . $author_lastname . "</h2>"; } }
Adding author’s last name to the post meta
This example adds the author’s last name to the post meta section below the post title.
function add_author_lastname_to_meta() { $author_lastname = get_the_author_lastname(); echo "Last name: " . $author_lastname; } add_action( 'genesis_entry_header', 'add_author_lastname_to_meta', 12 );
Displaying author’s last name in a custom author box
This example creates a custom author box that displays the author’s last name along with their bio.
function custom_author_box() { $author_lastname = get_the_author_lastname(); $author_bio = get_the_author_meta( 'description' ); echo "<div class='author-box'>"; echo "<h3>Author: " . $author_lastname . "</h3>"; echo "<p>" . $author_bio . "</p>"; echo "</div>"; } add_action( 'genesis_after_entry', 'custom_author_box' );
Displaying author’s last name in a custom widget
This example creates a custom widget that displays the author’s last name.
class Author_Last_Name_Widget extends WP_Widget { public function __construct() { parent::__construct( 'author_last_name_widget', 'Author Last Name Widget' ); } public function widget( $args, $instance ) { echo $args['before_widget']; echo $args['before_title'] . "Author's Last Name" . $args['after_title']; echo get_the_author_lastname(); echo $args['after_widget']; } } add_action( 'widgets_init', function() { register_widget( 'Author_Last_Name_Widget' ); });