Support

Account

Home Forums General Issues Remove whitespace

Solving

Remove whitespace

  • Hi,

    how can I do to remove whitespace (text nodes)?

    You can see here: https://flowersliving.com/2018_v1/a-florence-wedding-so-pretty-youd-swear-it-was-a-styled-shoot
    Top of the page, below the post title there are 3 circles with different colors: these are obtained by checkboxes choices, transformed in circles via css.
    Between each circle you can see the issue when you inspect the code…

    Many thanks,
    Pietro

  • I forgot to show you the code I use to display the field:

    <?php $colore = get_field(‘colore’);
    if( $colore ): ?>
    <?php foreach( $colore as $colore ): ?>
    <span class=”color-<?php echo $colore; ?>”></span>
    <?php endforeach; ?>
    <?php endif; ?>

  • The white-space is created because of the way you’ve formatted your code.

    Every time you close php ?>' and then open it again on a new line<?php `, the page outputs that new line. All of those open/close php tags are unnecessary.

    
    <?php 
      $colore = get_field('colore');
      if( $colore ):
        foreach( $colore as $colore ):
          ?><span class="color-<?php echo $colore; ?>"></span><?php 
        endforeach;
      endif;
    ?>
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Remove whitespace’ is closed to new replies.