Title: While Loop extra spaces in html output
Last modified: August 20, 2016

---

# While Loop extra spaces in html output

 *  [mklappen](https://wordpress.org/support/users/mklappen/)
 * (@mklappen)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/while-loop-extra-spaces-in-html-output/)
 * I have a while loop that is giving me some formatting issues when it renders 
   in browser. I am trying to list some posts (comma separated) in a paragraph tag.
 *     ```
       $postCount = 0;
       echo '<p>';
       while ( $platforms->have_posts() ) : $platforms->the_post();?>
       	<a href="<?php the_permalink()?>" title="<?php the_title();?>"><?php trim(the_title());?></a>
       	<?php
       	++$postCount;
       	if ($postCount < $platforms->found_posts) {
       		echo ", ";
       	}
       endwhile;
       echo '</p>';
       ```
   
 * However when I look at the HTML source, there’s all this extra white space that
   is adding an extra space in the browser view.
 *     ```
       <p>							<a href="mysite" title="TitleA">TitleA</a>
       	, 							<a href="mysite" title="TitleB">TitleB</a>
       	, 							<a href="mysite" title="TitleC">TitleC</a>
       	</p>
       ```
   
 * So instead of my format looking like this: TitleA, TitleB, TitleC
 * There is extra space before the comma.
    TitleA , TitleB , TitleC
 * Is there something in wordpress php that is causing each Title link to go to 
   a separate line? I would expect the source to look like this
    `<p><a href="mysite"
   title="TitleA">TitleA</a>, <a href="mysite" title="TitleB">TitleB</a>, <a href
   ="mysite" title="TitleC">TitleC</a></p>`

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [mklappen](https://wordpress.org/support/users/mklappen/)
 * (@mklappen)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/while-loop-extra-spaces-in-html-output/#post-3198587)
 * Of course the formatting of the HTML when I post here doesn’t show up how I see
   it, but the while loop outputs each “the_title()” on a separate line and there
   are extra spaces that’s causing more whitespace around my commas…
 * Thanks in advance for any help.
 *  Thread Starter [mklappen](https://wordpress.org/support/users/mklappen/)
 * (@mklappen)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/while-loop-extra-spaces-in-html-output/#post-3198588)
 * updated with “code” brackets so now it looks how I see it in source

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘While Loop extra spaces in html output’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [mklappen](https://wordpress.org/support/users/mklappen/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/while-loop-extra-spaces-in-html-output/#post-3198588)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
