Adding a custom field as a link to an elementor button
Support › MB Elementor Integrator › Adding a custom field as a link to an elementor buttonResolved
- This topic has 10 replies, 3 voices, and was last updated 2 years, 4 months ago by
Duffl.
-
AuthorPosts
-
March 2, 2022 at 6:24 PM #34231
Yasmine
ParticipantHello.
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?March 4, 2022 at 10:03 AM #34285Long Nguyen
ModeratorHi,
The same solution is here https://support.metabox.io/topic/displaying-repeater-fields-in-elementor/
March 6, 2022 at 6:02 PM #34340Yasmine
ParticipantOk, 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?
March 7, 2022 at 4:31 PM #34356Long Nguyen
ModeratorHi,
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; } );
March 7, 2022 at 5:11 PM #34359Yasmine
ParticipantHi 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!
March 29, 2022 at 12:13 AM #35344Yasmine
ParticipantHello - this shortcode has stopped working. I have checked against plugins, but don't understand why it would just stop? Any idea?
March 29, 2022 at 1:10 AM #35345Yasmine
ParticipantI 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...
March 30, 2022 at 10:27 AM #35365Long Nguyen
ModeratorHi,
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.
November 25, 2022 at 9:22 PM #39320Duffl
ParticipantHi 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
November 25, 2022 at 11:42 PM #39332Yasmine
ParticipantHey - 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 🙂
November 25, 2022 at 11:56 PM #39333Duffl
ParticipantHah, totally great, thank you Yasmine!!
-
AuthorPosts
- You must be logged in to reply to this topic.