Site logo

[Resolved] How to add nofollow to a dynamic data heading in templates?

Home Forums Support [Resolved] How to add nofollow to a dynamic data heading in templates?

Home Forums Support How to add nofollow to a dynamic data heading in templates?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2515326
    Laurentiu

    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

    #2515528
    David
    Staff
    Customer Support

    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

    #2515725
    Laurentiu

    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/

    #2516030
    Ying
    Staff
    Customer Support

    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?

    #2516037
    Laurentiu

    Working now, my mistake.
    Thank you!

    #2516063
    Ying
    Staff
    Customer Support

    No Problem 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.