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

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #34231
    YasmineYasmine
    Participant

    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?

    #34285
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The same solution is here https://support.metabox.io/topic/displaying-repeater-fields-in-elementor/

    #34340
    YasmineYasmine
    Participant

    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?

    #34356
    Long NguyenLong Nguyen
    Moderator

    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;
    } );
    #34359
    YasmineYasmine
    Participant

    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!

    #35344
    YasmineYasmine
    Participant

    Hello - this shortcode has stopped working. I have checked against plugins, but don't understand why it would just stop? Any idea?

    #35345
    YasmineYasmine
    Participant

    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...

    #35365
    Long NguyenLong Nguyen
    Moderator

    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.

    #39320
    DufflDuffl
    Participant

    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

    #39332
    YasmineYasmine
    Participant

    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 🙂

    #39333
    DufflDuffl
    Participant

    Hah, totally great, thank you Yasmine!!

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