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'm using the plugin WP UI on my custom post type to display the content in tabs. I'm doing this in the template for the custom post type not using the shortcode provided by the plugin. I'm also using Advanced Custom Fields for the fields on the custom post type.

However sometimes there won't be any content for the custom fields. The page will then display the tab but it will be empty.

In my template i have divs that are used to display the content in tabs. So in my template i have the div for the tab and then the custom field.

                <!-- Videos Tab -->

  <h3 class="wp-tab-title">Videos</h3>

  <div class="wp-tab-content">

        <?php the_field('videos'); ?>

   </div><!-- Close Videos --> 

Is it possible to hide the tab if there is no content in the custom field? i.e. not output the div so therefore it won't display the tab.

Thanks

So there's no confusion, the_field is a function used by advanced custom fields to display the contents of the custom field.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I have no experience with WP UI, but the following code might do the trick:

            <!-- Videos Tab -->

<h3 class="wp-tab-title">Videos</h3>

<?php if (get_field('videos') && get_field('videos') != "") { ?>

    <div class="wp-tab-content">

        <?php the_field('videos'); ?>

    </div><!-- Close Videos --> 

<?php } ?>
share|improve this answer
1  
I don't think it will work. the_field() do an echo() –  Kaaviar Nov 29 '11 at 16:30
    
I tried this but this just hides the tabs even if there is something in them. Also i've updated the question regarding the_field() –  Corbula Nov 29 '11 at 16:48
    
i changed my code - replaced the_field by get_field - i think this should work since get_field just returns the value instead of echoing... –  ptriek Nov 29 '11 at 17:05
add comment

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.