#HowTo : Adding a Separator to wp_list_categories : In WordPress, if you’re wanting to display your categories in a straight line i.e inline instead of an un-ordered list, Then the chances are you will need to have separator’s in between which also means you will have to search through the internet.

Since wp_list_categories doesn’t include a separator argument, you need to do a simple PHP string replace to add one in. And this is how I have done it on a site which I am just creating right now. (UPDATE: Link will be added so you guys can have a look at the real example)

#HowTo : Adding a Separator to wp_list_categories

 

 
 < ?php $needle = ''; $cat_list_args = array( 'echo' => __( 0 ), // sends output to variable
 'title_li' => __( '' ), // removes title of list (optional)
 'hierarchical' => __( 0 ), // makes subcategories not show as inner list items (optional)
 'exclude' => __( 1 ), // excludes uncategorized (optional)
 'child_of' => 6 // Replace with the ID of the parent category
 );
 $separator = ' / '; // fill in your separator here
 $cat_list_arr = wp_list_categories( $cat_list_args );
 $cat_list_mod = str_replace($needle,$needle.$separator,$cat_list_arr); // switch to $separator.$needle if you want separator inside a tag
 echo $cat_list_mod;
 ?>

 

I didn’t see any answers to this question on the WordPress forums so I thought I’d post the code I wrote here by mixing up hundred of different snippets.

On the other hand, if you want to hide the separator of your final list item, CSS pseudo-classes makes that super easy. See how I have targeted that last item and displayed as none.

ul li:last-child span.separator{ 
	display: none;
}