Site logo

[Resolved] Add Rel=Sponsored / Nofollow to dynamic post meta links

Home Forums Support [Resolved] Add Rel=Sponsored / Nofollow to dynamic post meta links

Home Forums Support Add Rel=Sponsored / Nofollow to dynamic post meta links

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2539630
    Thomas

    We’ve recently created a new post template for product reviews, and we have ‘buy now’ style buttons that are populated using post meta data. The buttons are Headlines (which displays the relevant meta data) inside a container.

    How can we set these as Rel=sponsored or nofollow, given there’s no clear place to select this option?

    Example review below.

    Thanks,
    Thomas

    #2539790
    David
    Staff
    Customer Support

    Hi there,

    for now you need tom use some PHP.

    1, Add this PHP Snippet to your site:

    
    add_filter( 'render_block', function( $block_content, $block ) {
      if ( 
        !is_admin() 
        && ! empty( $block['attrs']['className'] ) 
      ) {
        if ( strpos( $block['attrs']['className'], 'nofollow' ) !== false ) {
          $block_content= str_replace( 'href','rel="nofollow" href' , $block_content );
        }
        if ( strpos( $block['attrs']['className'], 'sponsored' ) !== false ) {
          $block_content= str_replace( 'href','rel="sponsored" href' , $block_content );
        }
    
      }
      return $block_content;
    }, 10, 2 );

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

    2. then select the block with the link and in Advanced > Additional CSS Class(es) add either: nofollow or sponsored

    #2540103
    Thomas

    Works a charm! Many thanks @David.

    Regards,
    Thomas

    #2540172
    David
    Staff
    Customer Support

    Glad to hear that!

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