Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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">
<div>
    <h1><?php echo get_post_meta(get_the_id(), 'header', true); ?> </h1> 
    <img src="<?php bloginfo('template_url'); ?>/images/pencil_Tip.gif" alt="">

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

Thanks in advance for any help.

share|improve this question

1 Answer 1

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

 
discard

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.