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!

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 );


Posted

in