Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Container link anchor text issue

  • I have a container element with 3 text elements inside it.

    For example:

    “text1”
    “text2”
    “text3”

    Now, text1 is a hyperlink.

    I want the container to be a hyperlink, so I set the container link to “wrapper”.

    This works as expected.

    However, the anchor text of the container shows as “text1 text2 text3”.

    It’s as if the hyperlink is being applied to all 3 text elements, which is not ideal for SEO purposes.

    How can I tell the container to use only “text1” as the anchor text?

    EDIT: Corrected some details.

  • Hi Parrot,

    To clarify, intrinsically, do you want the Container Block to be the link?

    If so, that’s possible through GenerateBlocks Pro. See: https://docs.generateblocks.com/article/container-links/

  • Yes, I want the container block to be the link, but I’ve done that. That’s not the issue here.

    The issue is with what happens after I apply the link to the container.

    Specifically, the anchor text changes from “text1” to “text1 text2 text3”.

    To clarify, text2 and text3 are NOT hyperlinks, so they should not be included in the anchor text.

  • Can you provide the link to where we can observe this?

  • Sorry, I just checked my template again and I realized none of the text elements are links. Only the container.

    My apologies.

    I guess what I’m asking is, how can I control the anchor text of the container? I don’t want it to use the entirety of the container contents as the anchor text.

  • Sure, I think screenshots would be best.

    I’ll add them to the private section below.

  • Added screenshots.

  • Is your 2nd screenshot from a Search Engine?

    Also, since Container Links is a GB Pro feature, can you also link your GB Pro account here for assistance with regard to GB Pro features??

  • It’s from an SEO tool (Ahrefs), but yes that’s how all search engines will see it also.

    My GB account is already linked upon signing up for this forum. And I am paid subscriber. What else do I need to do?

  • Sorry about that. I can confirm you have GB Pro.

    Try adding modify-link-title to the class list of the Container Link Block.

    Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    Then, add this snippet:

    add_filter( 'render_block', function( $block_content, $block ) {
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'modify-link-title' ) !== false ) {
    		$myreplace = '<a';
    		$myinsert = '<a title="' . 'YOUR TITLE HERE' . '"';
            $block_content = str_replace( $myreplace, $myinsert , $block_content );
        }
    
        return $block_content;
    }, 10, 2 );

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

    Let us know how it goes.

  • Thanks Fernando.

    Sorry if I misunderstood, but wouldn’t YOUR TITLE HERE need to be changed manually?

    If I got that wrong, how does it know which title to use for each container?

  • Yes, you’re correct.

    However, actually, just remembered that title attributes are allowed as custom attributes in GB Pro. Reference: https://docs.generateblocks.com/article/custom-attributes/

    Example: https://share.getcloudapp.com/YEuezdYn

    You can use that instead.

  • I appreciate your help and patience with this.

    I can’t help but wonder if this approach is more complicated than it needs to be.

    In theory, what if I just made the text element my link, and then simply used CSS to stretch that link around my container?

    Can we do that instead?

  • I think the title attribute should be good SEO-wise. Reference: https://www.searchenginejournal.com/link-title-attribute/

    But, if you want to stretch out the text, can you provide the link to the page in question? We’ll try to see if it’s a good idea and if it’s possible design-wise.

  • To be honest, I read through your links and I still don’t understand how to use the title attribute with the code you provided. Does that work dynamically?

    I’m adding a page from my site in the private information.

  • Hi there,

    try this instead.

    1. remove the container link.
    2. give the container an Advanced > CSS Class of: make-container-link
    3. add the link to the text element that you want to be in that link.
    3.1 Note there must only be one link in the container.
    4. Add this CSS:

    .make-container-link {
        position: relative;
    }
    .make-container-link a:before {
        content: '';
        position: absolute;
        inset: 0;
    }

    This will create a pseudo element on the link, that will cover the area of the container

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