Support

Account

Home Forums ACF PRO Url and Email field

Solving

Url and Email field

    • c-note

    • March 19, 2015 at 4:16 am

    Just curious but I can’t find these in the documentation, do they have any special properties? The Url field has the world globe icon but I can’t detect anything else..

  • They are just standard fields, nothing special from what I know. Just use your standard get_field and the_field to output the data.

    • Erica

    • November 5, 2015 at 12:24 pm

    Not to highjack a thread, but related to this, how would I output the email address (from a backend email field) on the front end, in a mailto: link? Example, let’s say in the back end there is information entered for John Doe, e-mail address is johndoe@test.com. On the front end, I want to display a link that says E-mail, with mailto:johndoe@test.com as the link. Thanks for any input!

  • To the first point, yes they are just standard fields but require that a valid URL or an email address be entered.

    second question

    
    <?php 
      <a href="mailto:<?php the_field('email_field_name'); ?>">E-Mail</a>
    ?>
    
    • Erica

    • November 6, 2015 at 7:30 am

    @hube2 Thank you! I will try that. Is there a way to do the same with a shortcode? I am creating a site for someone using the Divi theme, and putting the code into the page builder (even the ‘code’ module) isn’t working. They won’t want to be editing template files in the future.

  • acf has a simple shortcode that can be used in the content area in WP that is documented here http://www.advancedcustomfields.com/resources/shortcode/

    Basically it would be something like this when editing in text mode, but to be honest I don’t know if this will work with the changes that WP has recently made to the way shortcodes work. You’d have to try it.

    <a href='mailto:[acf field="field_name"]'>E-Mail</a>

    I’m not familiar with the Divi and don’t know if it will work there.

    • Erica

    • November 10, 2015 at 4:19 am

    @hube2 Thank you, the shortcode one works! For some reason, the php one doesn’t work.

  • The php one not working may have someting to do with the framework you’re using or some other incompatibility.

  • Hi there, I’ve tried both of these options and the mailto: link is not going anywhere?

    Is there anything I’m doing wrong? This is what I’ve entered into the Divi template:

    <i class=”fas fa-envelope” style=”color: #2e7df4; padding-right: 10px;”></i>[acf field="email"]

    and when I test it, it only prints to mailto:[acf field="email"] and not the email entered into the custom field.

    Any ideas?

  • @karlapizzica it depends on where you’re putting that code what the solution would be. Is that in a template somewhere or are you trying to put that into a field of some type?

  • Oh okay. So what I’m doing is I’ve created a template within Divi for a single post.

    The custom fields are within the template to be used whenever the user creates a post. I used it within the Divi Template builder which is essentially customising the template of custom pages. This one is single.php.

    I’ve provided a link for you to see what I mean:

    https://thehellodirectory.com/hello-mojo-app/

    You’ll see the right sidebar populated with custom fields (website, email, phone number etc).

  • 
    <i class="fas fa-envelope" style="color: #2e7df4; padding-right: 10px;"></i><?php echo do_shortcode('[acf field="email"]'); ?>
    
  • Hi there,

    When I use this:

    <a href='mailto:[acf field="email"]'>E-Mail</a>

    The mailto: is empty but when I just place the shortcode [acf field="email"] the email address is displayed as it should.. I’m using the DIVI builder.

    Any suggestions? it’s driving me nuts to put a simple email link in my page 🙁

    Thanks,
    Bertus.

  • Hi there,

    Did you ever solve this? I’m having the exact same issue trying to get a simple link to work.

  • Just in case anyone is interested in this – I managed to hack together a solution.

    I added the following code to the Divi functions.php file to create a simple shortcode. You then just add the shortcode [contact_email] into the code block in Divi:

    add_action('init', function(){
        add_shortcode('contact_email', function(){
            return '<a href="mailto:' . get_field('contact_email') . '">E-Mail</a>';
    
        });
    });
Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.