WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show the image only if there is info in the field. And the link around the image uses the info in the field. The mailto: field is coming up blank. So I'm guessing/hoping I'm doing something wrong with the way I'm printing/calling it. I would greatly appreciate any help.

<?php $email = types_render_field ("email");
          if ( $email ) { ?>
           <a href="mailto:<?php $email ?>"><img src="<?php bloginfo( 'template_url' ); ?>/images/icon-email.gif" width="24" height="24" /></a>
<?php } ?>

In case it's relevant, I'm using the Types plugin to create my custom fields.

share|improve this question


<?php $email ?>


<?php echo $email; ?>

as you need to echo the result of what's held within $email as the function types_render_field would be using return within the function (if you dig into its core) to return the data instead of directly printing it to screen.

<?php $email = types_render_field ("email");
          if ( $email ) { ?>
           <a href="mailto:<?php echo $email; ?>"><img src="<?php bloginfo( 'template_url' ); ?>/images/icon-email.gif" width="24" height="24" /></a>
<?php } ?>
share|improve this answer
Thanks very much. When I echo it, it pulls it out of the href link and displays email@address.com" (with the quote at the end, from the href code. Any idea how to prevent that from happening? – SBG Oct 17 '12 at 1:38
Sorry, add a semi-colon ; after your variable declaration - so <?php echo $email; ?> (snippet updated) – userabuser Oct 17 '12 at 4:51

I figured it out! It had to do with the way the custom field had been created. When it was an "email field", it gave me that big mess. When I made it just a single line text field, it was fine.

share|improve this answer
Hmm probably shouldn't have made a difference, it was more likely the missing semi-colon that was causing the improper output as mentioned in my update below. – userabuser Oct 17 '12 at 4:53
the semi-colon and echo helped with the field return, thanks. But the new problem that presented itself -- the inability for the field's value to exist within an href tag -- was fixed by changing the field type. – SBG Oct 18 '12 at 4:11
Peculiar to say the least. It shouldn't have an effect on printing the value within a href attribute, however, changing the field type still suffices. I wonder if adding true as in $email = types_render_field('email', true); would have any bearing? That aside, if the problem is now solved for you that's great, then you cane mark and close out this question. – userabuser Oct 18 '12 at 4:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.