WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set a default featured image for terms of a custom taxonomy.

I found this code but it is only good for categories and not for other terms:

<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>

<?php the_post_thumbnail('thumbnail'); ?>

<?php else :?>

<img src="whatever/directory/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" /> 

<?php endif;?>

How can I make this code also work for a custom taxonomy?

share|improve this question

Instead of using get_the_category() use get_terms() so something like this:

<img src="whatever/directory/<?php $terms = get_terms('TAXONOMY_NAME'); echo $terms[0]->term_name; ?>.jpg" /> 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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