WordPress.org

Ready to get started?Download WordPress

Forums

Show info from custom field only when there is a value? (3 posts)

  1. HorrorUK
    Member
    Posted 2 years ago #

    Hi all,

    I'm trying to get WP to only show information when there is a value in a custom field.

    For example, if I have an email address to show, the custom field would hold the email, but I also want to make it look a little neater by including some text:

    Email: me@here.com

    If there is no email address placed into the custom field, I don't want the Email: to appear and don't want to have a line break where it would have appeared.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    something like this for example:

    <?php if( $email = get_post_meta($post->ID,'email-field-key',true) ) echo 'Email: <a href="mailto: '.$email.'">'.$email.'</a><br />'; ?>

    adjust whatever key name you are using for the email custom field...

  3. HorrorUK
    Member
    Posted 2 years ago #

    Thank you, that did the job perfectly :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.