You are echoing the author link generator inside an already opened anchor tag, which is causing error. Try this code:
Method 1
<?php if ( !is_page() ) :
$author_posts_url = the_author_link();
$posts_by_title = sprintf(
__( 'Posts by %1$s ( @%2$s )', 'p2-breathe' ),
get_the_author_meta( 'display_name' ),
get_the_author_meta( 'user_nicename' )
); ?>
<a href="https://wordpress.stackexchange.com/questions/251479/<?php echo esc_url( $author_posts_url ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="author-avatar">
<?php echo get_avatar( $author_posts_url ); ?>
</a>
<?php endif; ?>
<div class="entry-meta">
<?php if ( ! is_page() ) : ?>
<a href="<?php echo get_author_posts_url(); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>
<?php endif; ?>
<span class="entry-date">
Noticed that i replaced echo esc_url( the_author_link() );
with get_author_posts_url()
which will only return the URL, not a full anchor.
You may also want to use get_author_posts_url(the_author_ID())
if the code didn’t work at the first place.
Method 2
If you are not running this code in a loop and don’t have access to the author ID, you can change the following line:
<a href="https://wordpress.stackexchange.com/questions/251479/<?php echo esc_url( the_author_link() ); ?>" title="<?php echo esc_attr( $posts_by_title ); ?>" class="entry-author"><?php the_author(); ?></a>
to:
<?php the_author_link(); ?>
Which will still return a link to author page, but without class="entry-author"
which i don’t think would be a great deal since you can tweak your css to achieve the same result.