Title: Adding separators to categories (existing code)
Last modified: August 20, 2016

---

# Adding separators to categories (existing code)

 *  Resolved [ggg377](https://wordpress.org/support/users/ggg377/)
 * (@ggg377)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/adding-separators-to-categories-existing-code/)
 * I have this php code to display categories:
 *     ```
       <span class="cat-links">
       <?php
       foreach((get_the_category()) as $category) {
           echo '<span id="'.$category->slug . '"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a></span>'; $separator = ' ';
       }
   
       ?>
       </span>
       ```
   
 * I looked up the codex for get_the_category and it says $separator = ‘ ‘; would
   add a space between the categories. But wherever I place it even when using the;
   symbols properly, it either does nothing or it loses the odd-colored tag with
   a different class in my example (test). I would appreciate all help or hints.
 * example: [http://goldenred.web44.net/](http://goldenred.web44.net/)

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/adding-separators-to-categories-existing-code/#post-3385025)
 * [http://codex.wordpress.org/Function_Reference/get_the_category](http://codex.wordpress.org/Function_Reference/get_the_category)
 * try:
 *     ```
       <span class="cat-links">
       <?php
       $separator = '';
       foreach((get_the_category()) as $category) {
           echo $separator . '<span id="' . $category->slug . '"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a></span>'; $separator = ' ';
       }
       ?>
       </span>
       ```
   
 *  Thread Starter [ggg377](https://wordpress.org/support/users/ggg377/)
 * (@ggg377)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/adding-separators-to-categories-existing-code/#post-3385029)
 * That did the trick alchymyth. Thanks a lot.

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

The topic ‘Adding separators to categories (existing code)’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [css](https://wordpress.org/support/topic-tag/css/)
 * [differently](https://wordpress.org/support/topic-tag/differently/)
 * [link](https://wordpress.org/support/topic-tag/link/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [styling](https://wordpress.org/support/topic-tag/styling/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * 2 replies
 * 2 participants
 * Last reply from: [ggg377](https://wordpress.org/support/users/ggg377/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/adding-separators-to-categories-existing-code/#post-3385029)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
