Archived topic
How to add nofollow to a dynamic data heading in templates?
5 replies · Started by Laurentiu on January 31, 2023
I have a custom block - content template.
I would like to add nofollow to the heading link: https://flyingassist.com/c/airfields-airports-in-austria/ but I can't find this option.
Adding a screenshot here: https://ibb.co/grx3bdB
Hi there,
1. Add this PHP Snippet to your site:
add_filter( 'render_block', function( $block_content, $block ) {
if (
! empty( $block['attrs']['className'] )
&& 'nofollow' === $block['attrs']['className']
) {
$block_content = str_replace( '<a ', '<a target="_blank" rel="nofollow" ', $block_content );
}
return $block_content;
}, 10, 2 );
How to add PHP: https://docs.generatepress.com/article/adding-php/
2. Select the block you have for your dynamic link and in Advanced > Additional CSS classes add: nofollow
Thank you, David. It works only partially. It adds the nofollow on the H2, and I don't have the option to add an actual link. Here is the page: https://flyingassist.com/c/airfileds-airports-in-california-united-states/
Hi there,
Just checked the page, I can see the nofollow class has been added to the H2 headline block correctly, but the PHP code David provided doesn't seem to be working.
How did you add the code?
Working now, my mistake.
Thank you!
No Problem :)