Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.