Author Box After Posts
Adds a box with the author avatar, name, biography and a link to their other posts at the end of single posts. Authors without a biography are skipped.
Opens WPIDE on
Code
add_filter( 'the_content', function ( $content ) {
if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$author_id = (int) get_post_field( 'post_author', get_the_ID() );
$bio = (string) get_the_author_meta( 'description', $author_id );
if ( '' === trim( $bio ) ) {
return $content;
}
$box = '<div class="wpide-author-box" style="display:flex;gap:16px;align-items:flex-start;margin-top:2em;padding:16px;border:1px solid rgba(0,0,0,.1);border-radius:6px;">';
$box .= get_avatar( $author_id, 72 );
$box .= '<div><p style="margin:0 0 .4em;"><strong>' . esc_html( get_the_author_meta( 'display_name', $author_id ) ) . '</strong></p>';
$box .= '<p style="margin:0;">' . wp_kses_post( $bio ) . '</p>';
$box .= '<p style="margin:.4em 0 0;"><a href="' . esc_url( get_author_posts_url( $author_id ) ) . '">More posts by this author</a></p></div></div>';
return $content . $box;
}, 20 );
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.