Site logo

Archived topic

Yoast link functionality doesn't work for links inside GP elements

10 replies · Started by George on October 30, 2022

Viewing posts 1–11 of 11

Yoast has a functionality where you can select a link and assign nofollow and sponsored link attributes.
https://i.imgur.com/ftEyMQh.png

The functionality is not there for links that exist on GP elements, though. Is there a solution for this? I have also raised a GitHub issue.

Hey George,

I'm sure Tom and Jean will take a look at the Github issue and respond there.

Thanks for mentioning it!

Can you recreate it on your end, Leo?

No response at the GitHub issue, can we treat that as a support request, I don't see getting a response anytime soon, Leo. It would help if you could recreate it at your end and comment on the issue.

Thanks David, why does GP have public set to off? What would happen if public was set to true?

The default $public value for all CPTs is false.
You only make a CPT public if it's required.
Its quite a special arg in that it declares its not for public use and its value is inherited by many other args eg.

Show in the main admin.
Show in the Menu builder
Is publicly queryable
Is included in Search results
Probably some other stuff too..

All of which we Elements does not require.

Ok, thanks, David, I will find another solution.

Be nice if WP added this to core links, its such an oversight by them.

I hope you find a good solution.

Yeah, true. Two ways to go about it:
1. Make use of a reusable block inside the element.
2. Filter the headline block with a class and add classes accordingly, like:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( !is_admin() && ('generateblocks/headline' === $block['blockName'] || 'core/paragraph' === $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 );

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

    return $block_content;
}, 10, 2 );

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

    return $block_content;
}, 10, 2 ); 

Good to see that George. Thanks for sharing!!

This archived topic is closed to new replies.