[Resolved] Postmeta email link for CPT using element->block->Content Template

Home Forums Support [Resolved] Postmeta email link for CPT using element->block->Content Template

Home Forums Support Postmeta email link for CPT using element->block->Content Template

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1929374
    Jeff

    I’m creating an archive page for a custom post type; ACF for custom fields.

    There’s a field named “contact_email”.

    I can successfully add a dynamic headline to display the email address.

    But when I try to create a mailto link, the system adds “http://” followed by the email address β€” instead of “mailto:”.

    Am I doing something wrong?

    Is there a workaround? How can I get GP Premium to use mailto?

    Thanks.

    #1930786
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    In your dynamic link, make sure it’s set to #.

    Then it should pull in the full mailto:you@you.com if you add it like that to the custom field.

    So the system will replace href="#" with href="your-custom-field-value".

    Let me know πŸ™‚

    #1963665
    Brenden

    This worked for me. Thank you!

    #1963903
    Tom
    Lead Developer
    Lead Developer

    No problem!

    #2049317
    Jason

    I’m a bit unsure about getting this to work.
    My ACF field is set as email type for validation, thus including ‘mailto:’ within the field content is prohibited. How should I set this up to enable this for the email and also for a phone field for ‘tel:’?

    #2050339
    Tom
    Lead Developer
    Lead Developer

    We would need to filter the output in that case.

    For example:

    add_filter( 'generate_dynamic_element_url', function( $url, $link_type, $source, $block ) {
        if ( 'post-meta' === $link_type ) {
             $meta_name = $block['attrs']['gpDynamicLinkCustomField'];
    
            if ( $meta_name && 'your-email-meta-field-name' === $meta_name ) {
                $url = 'mailto:' . $url;
            }
    
            if ( $meta_name && 'your-tel-meta-field-name' === $meta_name ) {
                $url = 'tel:' . $url;
            }
        }
    
        return $url;
    }, 10, 4 );
    #2050480
    Jason

    Thanks Tom,
    As always you came through with the goods, works a treat!
    Much appreciated

    #2051423
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! πŸ™‚

    #2455690
    Christian

    Hi Tom,

    I followed all your instructions, but did not achieve success. Regardless that it works straightforward to create nice author boxes, firstly, thanks for that ^.^/

    The Link button is set to #, the dynamic option (Link Type) is set to Author Meta and the Field Name is set to user_mail.

    Nevertheless, the button does not pull any mail afterwards, only the root domain.

    Do you have any ideas what this could be? All other links work (like LinkedIn).

    Thanks in advance,
    Chris

    #2455758
    David
    Staff
    Customer Support
    #2455770
    Christian

    Hey David, thank you for the reply!

    Good hint.

    I have now added the code to the customizer as follows (I hope this is the right approach):

    add_filter( ‘generate_dynamic_element_url’, function( $url, $link_type, $source, $block ) {
    if ( ‘post-meta’ === $link_type )

    $meta_name = $block[‘attrs’][‘gpDynamicLinkCustomField’];

    if ( $meta_name && ‘user_email’ === $meta_name ) {
    $url = ‘mailto:’ . $url;
    }
    }

    return $url;
    }, 10, 4 );

    The box is still pulling the domain. I will try it again later though πŸ™‚

    #2455951
    David
    Staff
    Customer Support

    Let us know how you get on!

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