I'm using

echo get_the_term_list( $post->ID, 'trpropcity', '', ' ', '' );

to show a taxonomy link, I'd like to make this instance of it only have the first letter capitalized, Cleveland not CLEVELAND, I realize I could just change the taxonomy, but I actually want it all caps everywhere else on the site, so I figured it would be best to just change it once. I've been playing with ucwords and strtolower but haven't had any success yet.


Build the links yourself:

$terms = get_the_terms($post->ID, 'trpropcity');
  foreach($terms as $term)
    echo '<a href="'.get_term_link($term, 'trpropcity').'">'.ucwords(strtolower($term->name)).'</a>';
  • @Chuck use ucfirst instead of ucwords – Azizur Rahman Jun 28 '11 at 10:34
  • this worked except one small issue, if a post has no taxonomy assigned to it I get a warning, Invalid argument supplied for foreach(). My guess is I need to check if it has a taxonomy assigned to it and based on that proceed to echo. I'll have to keep working on that. – Chuck Jun 29 '11 at 0:12
  • no, the issue is that a post may have no terms; use the updated code – onetrickpony Jun 29 '11 at 9:05

As an alternative way - you can just use CSS styling for taxonomy links, might work too.

  • actually this might be a better idea than using PHP; the only downside is that search engines see the caps – onetrickpony Jun 27 '11 at 16:32
  • Thanks, but this seems to only work if starting with lowercase to begin with, cleveland to Cleveland but not CLEVELAND to Cleveland. – Chuck Jun 29 '11 at 0:16

More of a php question but i use ucfirst

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.