Support Forum
Support › MB Elementor Integrator › Adding a custom field as a link to an elementor buttonResolved
Hello.
How do I add a "mailto: " link to an elementor button? I have "email" as a user custom field , and I can show the email as text in the form, but I wish to add the words "mailto:" before and add as a URL link in the button. How do I do this?
Hi,
The same solution is here https://support.metabox.io/topic/displaying-repeater-fields-in-elementor/
Ok, I have been trying to work this out for a while. I don't understand how the short code API should be applied. And should the collected email custom field be an email format, or is it better if it is text?
add_shortcode( 'make_a_mailto_email_link', function() {
$author_id = get_post_field( 'post_author', get_queried_object_id() );
$user_email = rwmb_meta( 'user_email', ['object_type' => 'user'], $author_id );
if ( empty( $post_id ) ) {
return '';
}
$output = ( 'mailto:'; $user_email );
return $output;
} );
`
Am I along the right tracks? And what do I need to do to make it work?
Hi,
I'm not sure if Elementor can render the shortcode in its form field. But you can add a full HTML code to link to the email address. Like this
add_shortcode( 'make_a_mailto_email_link', function() {
$author_id = get_post_field( 'post_author', get_queried_object_id() );
$user_email = rwmb_meta( 'user_email', ['object_type' => 'user'], $author_id );
$output = '<a href="mailto:' . $user_email . '">' . $user_email .'</a>';
return $output;
} );
Hi Long, thank you for your reply. It didn't work by making it html - but I got it working with:
add_shortcode( 'make_a_mailto_email_link', function() {
$author_id = get_post_field( 'post_author', get_queried_object_id() );
$user_email = rwmb_meta( 'user_email', ['object_type' => 'user'], $author_id );
$output = $user_email;
return $output;
} );
And adding "mailto:" in the advanced 'before' field in the dynamic options in elementor.
Thank you for your help though! Really happy this ones done!
Hello - this shortcode has stopped working. I have checked against plugins, but don't understand why it would just stop? Any idea?
I went back to a backup to compare metabox configuration and code and plugins - all exactly the same! With the only difference being elementor and meta box updates...
Hi,
The shortcode displays the user email as well in the post content of widget Text of Elementor. You might need to contact Elementor support to ask for help with this issue.
Hi I am sorry, I do not understand the solution posted in reply #34285
I would like to use email addresses dynamically, with mailto: link in elementor
Hey - I never got it working with merging the mailto: in output. But I got it working by just getting the user email with the shortcode and then in the page builder when adding the shortcode link, click advanced and add "mailto:" beforehand 🙂
Hah, totally great, thank you Yasmine!!