[Resolved] Yoast link functionality doesn’t work for links inside GP elements

Home Forums Support [Resolved] Yoast link functionality doesn’t work for links inside GP elements

Home Forums Support Yoast link functionality doesn’t work for links inside GP elements

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2394170
    George

    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.

    #2394320
    Leo
    Staff
    Customer Support

    Hey George,

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

    Thanks for mentioning it!

    #2394344
    George

    Can you recreate it on your end, Leo?

    #2404004
    George

    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.

    #2404568
    David
    Staff
    Customer Support

    Hi George,

    see my reply to the Git here:

    https://github.com/tomusborne/gp-premium/issues/374#issuecomment-1305424330

    To cover, GP doesn’t stop those options from being displayed, Yoast simply doesn’t load on post types that are not public.

    #2404586
    George

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

    #2404647
    David
    Staff
    Customer Support

    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.

    #2404693
    George

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

    #2404742
    David
    Staff
    Customer Support

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

    I hope you find a good solution.

    #2404976
    George

    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 ); 
    #2405935
    David
    Staff
    Customer Support

    Good to see that George. Thanks for sharing!!

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