Core Post Author Block Linked to Author Page

Make sure your WordPress post author block links to the author page with this easy code snippet! Learn how to add a link to the core post author block and dynamically wrap the content with a link to the author page.

Make sure your WordPress post author block links to the author page with this easy code snippet!

The core post Author block does not currently link to the author page. The following code filters the contents of the post author block and dynamically wraps the block with a link to the author page.

add_filter( 'render_block', function ( $block_content, $block, $instance ) {
	if ( ( $block['blockName'] ?? '' ) !== 'core/post-author' ) return $block_content;
	if ( is_author() ) return "<h1>$block_content</h1>";

	$post_id    = $instance->context['postId'];
	$author_id  = get_post_field( 'post_author', $post_id );
	$author_url = get_author_posts_url( $author_id );

	return <<<htm
<div class="wp-block-post-author--link">
  <a href="$author_url">$block_content</a>
</div>
htm;
}, 10, 3 );

Let’s talk.

Send me your site and what you need. You’ll get a plain answer.

hello@sunnymorgan.com

Hawaiʻi 808.634.5440North Carolina 828.414.8090