Archived topic
Replace link to Author page
24 replies · Started by Dave on February 9, 2023
I currently have these two snippets activated, which pull my headshot into the byline:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date_output', function( $date ) {
printf(
'<span class="meta-gravatar">%s</span>',
get_avatar( get_the_author_meta( 'ID' ) )
);
echo '<span class="meta-data">';
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
echo $date;
echo '</span>';
} );
function lh_page_hero_gravatar() {
ob_start();
global $post;
$author_id = $post->post_author;
?>
<div class="page-hero-gravatar">
<?php echo get_avatar( $author_id ); ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'page_hero_gravatar','lh_page_hero_gravatar' );
Hi there,
remove the function that Ying provided.
Then replace this:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date_output', function( $date ) {
printf(
'<span class="meta-gravatar">%s</span>',
get_avatar( get_the_author_meta( 'ID' ) )
);
echo '<span class="meta-data">';
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
echo $date;
echo '</span>';
} );
with:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date_output', function( $date ) {
if ( get_the_author_meta( 'ID' ) == 1 ) {
$author_url = 'https://www.irreverentgent.com/about-dave-bowden/';
} else {
$author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
}
printf(
'<span class="meta-gravatar">%s</span>',
get_avatar( get_the_author_meta( 'ID' ) )
);
echo '<span class="meta-data">';
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
$author_url,
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
echo $date;
echo '</span>';
} );
On this line: if ( get_the_author_meta( 'ID' ) == 1 ) { you need to change the 1 to match your user ID.
I get:
Don't Panic
The code snippet you are trying to save produced a fatal error on line 21:
Unclosed '{' on line 2
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.
Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
Do you have any code before that function ?
No I placed the code in a Code Snippets snippet exactly as you posted … except edited my page info for the author url and changed the ID to mine.
Hi Scott,
I just tested David's code, there is no error.
Can you show the exact code you are using? Please wrap it with the code tags.
You’re right. When I copied Davids code I didn’t get all of it copied. The last 3 lines (not including the blank lines) didn’t get copied. I works just fine.
The only thing is now after this is in place My picture, name, and date are all squished side by side. But Dave’s, the original poster, idea is better than the one I was using previously.

The new code David provided worked for me. Thanks David and Ying!
Glad to hear that Dave.
Scott if you want to raise a new topic i can take a look at your site and see what CSS is required to format that.