- This topic has 11 replies, 6 voices, and was last updated 1 year, 3 months ago by David.
-
AuthorPosts
-
September 13, 2021 at 1:40 pm #1929374Jeff
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.
September 14, 2021 at 6:53 pm #1930786TomLead DeveloperLead DeveloperHi 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="#"
withhref="your-custom-field-value"
.Let me know π
October 14, 2021 at 12:17 pm #1963665BrendenThis worked for me. Thank you!
October 14, 2021 at 7:44 pm #1963903TomLead DeveloperLead DeveloperNo problem!
December 14, 2021 at 4:48 pm #2049317JasonI’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:’?December 15, 2021 at 11:38 am #2050339TomLead DeveloperLead DeveloperWe 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 );
December 15, 2021 at 3:30 pm #2050480JasonThanks Tom,
As always you came through with the goods, works a treat!
Much appreciatedDecember 16, 2021 at 2:41 pm #2051423TomLead DeveloperLead DeveloperGlad I could help! π
December 9, 2022 at 3:55 am #2455690ChristianHi 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,
ChrisDecember 9, 2022 at 5:02 am #2455758DavidStaffCustomer SupportHi there,
did you update the meta names in Toms code here ?
December 9, 2022 at 5:17 am #2455770ChristianHey 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 π
December 9, 2022 at 7:30 am #2455951DavidStaffCustomer SupportLet us know how you get on!
-
AuthorPosts
- You must be logged in to reply to this topic.