Support

Account

Home Forums General Issues How to print email link so it's active

Solved

How to print email link so it's active

  • In my template I can get my email field to print out just fine. However, I can’t figure out how to get it to print with an link. Help?

    My code:

    echo '<td>';
    											echo '<i class="fa fa-envelope"></i>' . ' ';
    											echo the_field('contact_email');
    											echo '<br />';
    										echo '</td>';

  • Try this:

    <?php $email = get_field('contact_email'); ?>
      <td>
       <i class="fa fa-envelope"></i>
        <a href="mailto:<?php echo $email; ?>" rel="nofollow" title="Email me"><?php echo $email; ?></a><br />
      </td>

    🙂

  • Thanks, Ben! Unfortunately that didn’t work either. I tried merging your code and mine and the page wouldn’t load. Hmmm…!

  • Tell me more, where is the email field located within your dashboard on a page? Or on a options page? Are you trying to get the field from the page where the field is located?

    Post more of your code. I will take a look at it and see if I can sort it out. 🙂

  • This code is going on a members listing page which is calling in information frm individual member pages. Here’s the only unique code on my members_directory.php file.

    
    <?php
    
    						$posts = get_posts(array(
    							'numberposts' => -1,
    							'post_type' => 'library',
    							'orderby'     => 'title',
    							'order'     => 'asc',
    						));
    
    						if($posts)
    						{
    								foreach($posts as $post)
    								{
    
    								echo '<table class="members">';
    								echo '<thead>';
    								echo '</thead>';
    								echo '<tbody>';
    									echo '<tr>';
    										echo '<td colspan="3">';
    											echo '<h2><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></h2>';
    										echo '</td>';
    
    									echo '</tr>';
    									echo '<tr>';
    										echo '<td colspan="3">';
    											echo '<strong>Parent Organization:</strong>' . ' ';
    											echo the_field('parent_organization');
    											echo '<br />';
    										echo '</td>';	
    									echo '</tr>';
    									echo '<td colspan="3">';
    											echo '<strong>Address:</strong>' . ' ';
    											echo the_field('address');
    											echo '<br />';
    											echo '</td>';
    										echo '</tr>';
    									echo '<tr>';
    										echo '<td>';
    											echo '<strong>Contact:</strong>' . ' ';
    											echo the_field('contact_name');
    											echo '<br />';
    										echo '</td>';
    										echo '<td colspan="1">';
    											echo '<i class="fa fa-phone"></i>' . ' ';
    											echo the_field('contact_phone');
    											echo '<br />';
    										echo '</td>';
    										echo '<td colspan="1">';
    											echo '<i class="fa fa-envelope"></i>' . ' ';
    											echo the_field('contact_email');
    											echo '<br />';
    										echo '</td>';
    										echo '<tr>';
    
    									echo '</tr>';
    								echo '</tbody>';
    							echo '</table>';
    								}
    								
    						}
    
    					?>
  • Was that last reply supposed to be marked private? :-0

  • Oops, I thought that meant it was private to just you!

  • Try changing
    echo the_field('contact_email');

    to

    printf('<a href="mailto:%s" title="Email Me" rel="nofollow">%1$s</a>', get_field("contact_email"));

  • You are awesome, sir! I really appreciate it. This was driving me up the wall.

  • Glad it worked. 🙂

    This plugin is awesome and has changed my life. So I figure I should give back where I can be of assistance. 🙂

  • How are you using it? I installed it to create members pages.

  • I use it to create fields for the easy adding/editing of content all over a website.

    I have really only used a few of the field types (text, image, url, text area, wysiwyg and the repeater field)

    I used to make a lot of widget based themes before I found ACF. 😛

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘How to print email link so it's active’ is closed to new replies.