/* Pull category for each unique post using the ID */ $terms = get_the_terms( $post->ID, 'project_categories' ); if ( $terms && ! is_wp_error( $terms ) ) : $links = array(); foreach ( $terms as $term ) { $links[] = $term->name; } $tax_links = join( " ", str_replace(' ', '-', $links)); $tax = strtolower($tax_links); else : $tax = ''; endif; //or for when you need to do a str_replace on more than one item $search = array(' ', '&', 'amp;'); $replace = array('-', 'and',''); $tax_links = join( " ", str_replace($search, $replace, $links)); $tax = strtolower($tax_links);