Make span class disappear when custom field is empty in wordpress

Posted in: Newspaper
Post count: 101

Hi,

I have been adding some additional custom field values (with the acf plugin), to the flex block 1 module located in /includes/modules/td_module_flex_1.php

I am trying to write a code that makes a span class disappear if the custom field is empty. Via css I’m adding a comma, since the field concertlocation comes behind earlier metadata.

However if I program it like the code below, the span class simply doesn’t show up at all. the this->post_ID is necessary since the data is to be shown on an overview page, where some articles don’t have that field “concertlocatie”. What am I missing here, anyone ?

<span class="td-author-date">
<?php if( $author_photo != '' ) { echo $this->get_author_photo(); } ?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php $concertlocatie = the_field( "concertlocatie" , $this->post->ID ); //etc...?>
<?php if ( $concertlocatie ) : ?><span class="metacelocation"><?php echo $concertlocatie; ?><?php endif; ?></span>
<?php echo $this->get_comments();?>
</span>
</div>

the css

.home .metacelocation:before,
.category-306 .metacelocation:before {
content: ', ';
text-transform: none;
font-weight: normal;
color: #aaa;
display: inline-block;
position: relative;
top: 2px;
}

Post count: 20688
Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.