Site logo

Archived topic

Duplicate author bios

8 replies · Started by Milo Lam on June 8, 2021

Viewing posts 1–9 of 9

Hi,
I was following this tutorial from Leo: https://www.youtube.com/watch?v=4x6CjGOyagc.
The results were good but I noticed that I have two author bios now here. I'm using RankMath as an SEO plugin, maybe there's a setting that's causing the problem there?

Hi Milo,

Can you link us to a sample page in question to inspect where the duplicate author box may be coming from?

You can use the private information text field to provide the site details. :D

Yeah definitely!

Ah I see now. Thanks.

The second, stylized one is something hooked in from a Block element.

The first one you see is a filtered version of the footer meta of single post pages.

This one isn't the default behavior of footer meta. By default, the author is rendered on the header meta. Perhaps you have a filter that moves the author to the footer meta and another filter to change the styling of the author output to add in the avatar.

That said, can you check your site's code snippets or functions.php for any filters related to what I've mentioned? Let us know.

Aha! I found the culprit. Should be this code right here:

add_filter( 'generate_post_author_output', function() {
    return sprintf( ' <span class="byline">%1$s</span>',
        sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<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() ),
            get_avatar( get_the_author_meta( 'ID' ) )
        )
    );
} );
add_filter( 'generate_header_entry_meta_items', function( $items ) {
    return array(
        'categories',
		'date'
    );
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    return array(
        'author',
		'comments-link'
    );
} );

add_filter( 'generate_post_date_output', function($post_date){
	$post_date = sprintf(
		'<time class="entry-date published" datetime="%1$s"><span class="entry-date">%2$s</span><span class="entry-month">%3$s</span></time>',
		esc_attr( get_the_date( 'c', $id ) ),
		esc_html( get_the_date( 'd', $id ) ),
		esc_html( get_the_date( 'M', $id ) )
	);

	return $post_date;
},15,2);

This is used to achieve the author meta stuff on my blog category page (link in private field). Is there a way for the two to play nice? Thanks

Ah that's definitely it.

You can see the generate_footer_entry_meta_items filter containing 'author' which effectively moves the meta item from header to footer.

generate_post_author_output filter snippet then filters the author output, adding the avatar by getting it from get_avatar( get_the_author_meta( 'ID' ) ).

This is used to achieve the author meta stuff on my blog category page (link in private field). Is there a way for the two to play nice? Thanks

We can edit the condition so the filter only applies to archive pages and the blog index page.

Example:

add_filter( 'generate_post_author_output', function($output) {
	if(is_home() || is_archive() ){
		$output = sprintf( ' <span class="byline">%1$s</span>',
			sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<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() ),
				get_avatar( get_the_author_meta( 'ID' ) )
			)
		);
	}
    return $output;
} );
add_filter( 'generate_header_entry_meta_items', function( $items ) {
	if(is_home() || is_archive() ){
		return array(
			'categories',
			'date'
		);
	}
	return $items;
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
	if(is_home() || is_archive() ){
		return array(
			'author',
			'comments-link'
		);
	}
	return $items;
} );

We're basically adding the condition if(is_home() || is_archive() ) which basically tells the code to do this and that when the page is the blog index page or if its an archive page. :)

Mhm, that seems to get it done. But the post date on the blog category page breaks.

Ope nevermind the filter worked now! Thank you

Nice one. Glad you go it sorted. :)

This archived topic is closed to new replies.