Site logo

Archived topic

Single Post Header without link to author archive

3 replies · Started by Martin U on May 19, 2019

Viewing posts 1–4 of 4

Hi Tom and wonderful Generatepress team,

I use elements a lot to build custom headers for different pages / post. This works like a charme thank you so much. I do come across one issue

If using the {{post_author}} field on a single post header, I get the author name linking to the author archive.

I don't want a link to the author archive, I want simply the author name, no links. That is all.

For the blog index page I have added this to the function php

add_filter( 'generate_post_author_output','tu_no_author_link' );
function tu_no_author_link() {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
			__( 'by','generatepress'),
			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() )
		)
	);
}

This removes the link to the author archive for the blog index page. But I still get the link to the author archive on the single blog pages when using {{post_author}}in the custom header.

How do I get rid of the of the link to the author archive, I would like to see only the author name without a link to the author archive.

Best

Martin

BTW Is there a place for feature requests/suggestions?

Hi there,

Give this function a try:

add_filter( 'generate_page_hero_post_author', function() {
    global $post;
    $author_id = $post->post_author;

    return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-name" itemprop="name">%s</span></span>',
        esc_html( get_the_author_meta( 'display_name', $author_id ) )
    );
} );

Let me know :)

Worked like a charme, thank you so much, Tom.

You're welcome :)

This archived topic is closed to new replies.