Site logo

Archived topic

Add rel="author" to dynamic data

3 replies · Started by Trey on February 13, 2023

Viewing posts 1–4 of 4

I am using Headline dynamic data to display the author name and link to the author archives in my content template block element for my posts. I would like to include rel="author" in the a href to the author archives. Please let me know how I can achieve this.

Thanks

Hi Trey,

Try adding add-author-rel to the class list of the Block.

Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

Then, add this snippet:

function db_rerender_link( $block_content, $block ) {
	if(!is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'add-author-rel' ) !== false  ) {
			$my_search='href="';
			$my_replace='rel="author" href="';
			$new_content = str_replace($my_search, $my_replace, $block_content);
			return $new_content;
	}
    return $block_content;
}
 
add_filter( 'render_block', 'db_rerender_link', 10, 2 );

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

That worked like a charm! Thanks Fernando

You're welcome, Trey!

This archived topic is closed to new replies.