Answer the question
In order to leave comments, you need to log in
How to make a div not displayed if a custom field is empty?
Good evening.
The situation is what:
There is a code that displays a table. It has a line and two cells.
1st cell constant: icon + title
2nd cell variable: custom ACF field.
<tr class="tr01">
<td><img class="harimg" src="http://kosmosauto.com/wp-content/uploads/2016/02/har011.png" /> Привод:</td>
<td><?echo get_post_meta($post->ID, 'har01', true);?></td>
</tr>
echo get_post_meta($post->ID, 'har01', true);
<tr class="tr01">
Answer the question
In order to leave comments, you need to log in
Everything is as WP_Panda says, only you can optimize it + if it's ACF, then it's better not through get_post_meta, but through get_field/the_field:
<?php if( ! empty( get_field( 'har01' ) ) ) : ?>
<tr class="tr01">
<td><img class="harimg" src="http://kosmosauto.com/wp-content/uploads/2016/02/har011.png" /> Привод:</td>
<td><?php the_field( 'har01' ); ?></td>
</tr>
<?php endif; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question