• Resolved Amy

    (@amyn)


    I am so close to getting this string to work (i think). Being as I am not a PHP guru can someone point out my mistake here:

    echo '<span class="email">';
    if (  get_post_meta($post->ID, "email", true)  ) :  echo 'Email: ', '<a href="'get_post_meta($post->ID, "email");'">' get_post_meta($post->ID, "email"); '</a>';  endif;
    echo '</span>';
Viewing 9 replies - 1 through 9 (of 9 total)
  • echo '<span class="email">';
    if (  get_post_meta($post->ID, "email", true)  ) :  echo 'Email: ', '<a href="mailto:'get_post_meta($post->ID, "email");'">' get_post_meta($post->ID, "email"); '</a>';  endif;
    echo '</span>';
    Thread Starter Amy

    (@amyn)

    Whoops, can believe I forgot the “mailto:” in there. DOH!
    But it is still giving me the same syntax error, overall:

    unexpected T_STRING, expecting ‘,’ or ‘;’

    Try:

    echo '<span class="email">';
    if (  get_post_meta($post->ID, "email", true)  ) echo 'Email: ', '<a href="mailto:'get_post_meta($post->ID, "email");'">' get_post_meta($post->ID, "email"); '</a>';  echo '</span>';

    Thread Starter Amy

    (@amyn)

    That did not work either. πŸ™
    Same error output again.

    Your concatenation was all wrong:

    echo '<span class="email">';
    if (  get_post_meta($post->ID, "email", true)  ) echo 'Email: <a href="mailto:' . get_post_meta($post->ID, "email") . '">'  . get_post_meta($post->ID, "email") . '</a>';
    echo '</span>'

    Thread Starter Amy

    (@amyn)

    Sorry for being a pain…I am trying every which way but still the last suggestion is still not working. Giving me this now:

    unexpected T_ECHO, expecting ‘,’ or ‘;’

    There’s a missing ; after echo '</span>'.

    Thread Starter Amy

    (@amyn)

    Thank you very much for your help esmi! Can’t believe I missed that. Must’ve been staring at it for too long.

    When I corrected that, the page finally displayed but that code outputted:
    “Email: Array”

    I added in the “true” on all and it works perfect now. Here is my complete code now:

    echo '<span class="email">';
    if (  get_post_meta($post->ID, "email", true)  ) echo 'Email: <a href="mailto:' . get_post_meta($post->ID, "email", true) . '">'  . get_post_meta($post->ID, "email", true) . '</a>';
    echo '</span>';

    Thanks again!

    Glad to hear that you got it working. πŸ™‚

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Linkable Email Custom Field’ is closed to new replies.