Forums

[resolved] CSS custom field help (3 posts)

  1. foxeye
    Member
    Posted 2 years ago #

    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.

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    <?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; ?>
  3. foxeye
    Member
    Posted 2 years ago #

    veeeery happy. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic