WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to hide or show an HTML widget I built depending on whether someone adds custom fields to a page via WP Admin. Is this possible?

I'd like to do this in my HTML widget template (tips.php): check if there is a value for each of the custom fields in this template. If there isn't, hide this html from view. Otherwise, if there is custom field text, show the widget.

Here's my code:

<aside id="tipContainer">
    <h1><?php echo get_post_meta(get_the_id(), 'header', true); ?> </h1> 
    <img src="<?php bloginfo('template_url'); ?>/images/pencil_Tip.gif" alt="">

    <p> <?php echo get_post_meta(get_the_id(), 'content', true); ?> </p>

Thanks in advance for any help.

share|improve this question
up vote 1 down vote accepted

You can call get_post_meta inside of a conditional statement and display data depending on the field value (empty or set), check the sample loop in the Codex

share|improve this answer
Cool, thanks @Mario - that worked! – Mark Bubel Jun 14 '12 at 18:28
glad being of help :) – Mario Peshev Jun 14 '12 at 18:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.