• Resolved JaneLitte

    (@janelitte)


    I need some coding help here. I want to capture a custom field and using an “if not null statement echo output in a link form”. Here’s what I thought would work but does not:

    <?php if ( $wpcm_number_facebook != '' ) { echo '<li><span class="number">'<a href=\"' . $wpcm_number_facebook. '\" /> (facebook) </a>' </li>'; } ?>

Viewing 1 replies (of 1 total)
  • <?php
    // $fieldnm is null if the custom field doesn't exist
    $fieldnm = get_post_meta($post->ID,'yourfieldname',true);
    
    // If the field exists
    if($fieldnm) { ?> YOURHTMLHERE <?php } 
    
    // Field is null (doesn't exist)
    else { ?> SOMEOTHERHTML <?php }
    ?>

    Or using echo..

    <?php
    // $fieldnm is null if the custom field doesn't exist
    $fieldnm = get_post_meta($post->ID,'yourfieldname',true);
    
    // If the field exists
    if($fieldnm) { echo 'something to echo'; } 
    
    // Field is null (doesn't exist) // Remove if not needed
    else { echo 'the field is null'; }
    ?>

    Hope that helps…

    Update ‘yourfieldname’ with your actual custom field name.

Viewing 1 replies (of 1 total)

The topic ‘adding url (or <a href code) in an echo statement’ is closed to new replies.