Site logo

Archived topic

Add nofollow attribute to links in element >block> site footer

3 replies · Started by Rostyslav on July 28, 2022

Viewing posts 1–4 of 4

Hello,

I have created a block element site footer and I would like to add attribute to some of the links like "Privacy Policy". I can't find that option in the editor.

How can I achieve that?

Thanks

Hi there,

The privacy policy in your site footer seems added using a menu list block.

If so, GP has no control over it.

I would suggest using the GB buttons block to manually add links so that you can edit the attribute individually for each link.

Hi Rostyslav,

Try adding add-nofollow to the class list of the Headline Block in its advanced settings.

Then, add this snippet:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( !is_admin() && 'generateblocks/headline' === $block['blockName'] && ! empty( $block['attrs']['className'] ) && 'add-nofollow' === $block['attrs']['className'] ) {
        $block_content = str_replace( '<a ', '<a rel="nofollow" ', $block_content );
    }

    return $block_content;
}, 10, 2 );

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

This archived topic is closed to new replies.