Title: CSS custom field help
Last modified: August 19, 2016

---

# CSS custom field help

 *  Resolved [foxeye](https://wordpress.org/support/users/foxeye/)
 * (@foxeye)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/css-custom-field-help/)
 * 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](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/css-custom-field-help/#post-1438316)
 *     ```
       <?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](https://wordpress.org/support/users/foxeye/)
 * (@foxeye)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/css-custom-field-help/#post-1438477)
 * veeeery happy. Thanks!

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

The topic ‘CSS custom field help’ is closed to new replies.

## Tags

 * [Blank](https://wordpress.org/support/topic-tag/blank/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [empty](https://wordpress.org/support/topic-tag/empty/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 2 participants
 * Last reply from: [foxeye](https://wordpress.org/support/users/foxeye/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/css-custom-field-help/#post-1438477)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
