Make span class disappear when custom field is empty in wordpress
-
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. (so; “august 20 2018, Pukkelpop” should be an example of end result)
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; }
The page I need help with: [log in to see the link]
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Make span class disappear when custom field is empty in wordpress’ is closed to new replies.