• Resolved foxeye

    (@foxeye)


    Trying to style a custom field containing an url. I use a button trick with a href class and inline span. Problem is that in case the field is empty it now shows the css elements like the background images. code:

    <?php $weblink = get_post_meta($post->ID, 'weblink', true); ?>
    <a href="<?php echo $weblink; ?>" class="button" target="_blank"><span>button text</span></a>

    The “a href” code only needs to be printed in case the custom field is not empty, else do nothing. I’m not a coder but I’m sure this can be done in a simple way. Thanks for reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    <?php $weblink = get_post_meta($post->ID, 'weblink', true); ?>
    <?php if($weblink != '') : ?>
    <a href="<?php echo $weblink; ?>" class="button" target="_blank"><span>button text</span></a>
    <?php endif; ?>
    Thread Starter foxeye

    (@foxeye)

    veeeery happy. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CSS custom field help’ is closed to new replies.