- This topic has 24 replies, 4 voices, and was last updated 3 years, 2 months ago by
David.
-
AuthorPosts
-
February 10, 2023 at 8:47 am #2528633
Dave
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' );February 11, 2023 at 5:11 am #2529306David
StaffCustomer SupportHi 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 the1to match your user ID.February 11, 2023 at 6:24 am #2529372Scott
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.February 11, 2023 at 9:26 am #2529607David
StaffCustomer SupportDo you have any code before that function ?
February 11, 2023 at 12:12 pm #2529756Scott
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.
February 11, 2023 at 1:11 pm #2529802Ying
StaffCustomer SupportHi 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.
February 11, 2023 at 1:39 pm #2529821Scott
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.
February 11, 2023 at 1:47 pm #2529826Scott
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.
February 11, 2023 at 2:49 pm #2529876Dave
The new code David provided worked for me. Thanks David and Ying!
February 12, 2023 at 4:20 am #2530182David
StaffCustomer SupportGlad 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. -
AuthorPosts
- You must be logged in to reply to this topic.