Author Bio at the Top of Author Archives
Shows the author's photo, name, number of posts, bio and website at the top of their author archive, turning it into a proper profile page.
Opens WPIDE on
Code
// Size of the author photo in pixels.
$wpide_author_archive_avatar = 96;
$wpide_author_archive_box = function () use ( $wpide_author_archive_avatar ) {
$user = get_queried_object();
if ( ! $user instanceof WP_User ) {
return '';
}
$bio = get_the_author_meta( 'description', $user->ID );
$website = $user->user_url;
$count = count_user_posts( $user->ID, 'post', true );
$html = '<section class="wpide-author-intro" style="display:flex;flex-wrap:wrap;gap:1em;align-items:flex-start;margin:0 0 2em;padding:1.25em;border:1px solid rgba(127,127,127,.3);border-radius:8px;">';
$html .= get_avatar( $user->ID, $wpide_author_archive_avatar, '', '', array( 'extra_attr' => 'style="border-radius:50%;flex:0 0 auto;"' ) );
$html .= '<div style="flex:1 1 240px;min-width:0;">';
$html .= '<p style="margin:0 0 .25em;"><strong>' . esc_html( $user->display_name ) . '</strong> · ' . esc_html( sprintf( _n( '%s post', '%s posts', $count ), number_format_i18n( $count ) ) ) . '</p>';
if ( '' !== $bio ) {
$html .= wpautop( wp_kses_post( $bio ) );
}
if ( $website ) {
$html .= '<p style="margin:.5em 0 0;"><a href="' . esc_url( $website ) . '" rel="me">' . esc_html( preg_replace( '#^https?://(www\.)?#', '', untrailingslashit( $website ) ) ) . '</a></p>';
}
return $html . '</div></section>';
};
// Classic themes: before the list of posts.
add_action( 'loop_start', function ( $query ) use ( $wpide_author_archive_box ) {
static $done = false;
if ( $done || wp_is_block_theme() || ! $query->is_main_query() || ! is_author() || is_paged() ) {
return;
}
$done = true;
echo $wpide_author_archive_box(); // phpcs:ignore WordPress.Security.EscapeOutput -- escaped when built.
} );
// Block themes: after the archive title.
add_filter( 'render_block_core/query-title', function ( $content ) use ( $wpide_author_archive_box ) {
static $done = false;
if ( $done || ! is_author() || is_paged() ) {
return $content;
}
$done = true;
return $content . $wpide_author_archive_box();
} );
Notes
Classic themes get it above the first post, block themes after the archive title; it appears on the first page only.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.