0

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.

1 Answer 1

1

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

1
  • glad being of help :) Commented Jun 14, 2012 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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