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'm using the following code to display images based on the category id:

if (is_category( 'web-design' )){
<img src="<?php bloginfo('template_directory'); ?>/images/slider_webdesign.png" title="خدمات تصميم وتطوير المواقع" height="200px" width="960px" />
}else if (is_category( 'printing' )){
<img src="<?php bloginfo('template_directory'); ?>/images/slider_printing.png" title="تصميم مطبوعات" height="200px" width="960px" />
}else if (is_category( 'online-marketing' )){

I would like to make an array of only one condition to display an image with the category slug, is that possible?

share|improve this question
FYI, bloginfo('template_directory') is deprecated. Recommended function now is get_template_directory_uri(). – mrwweb May 16 '12 at 20:59
up vote 1 down vote accepted

is_category() takes an array as arguments if you want to check for more than one category. But you can make it even easier with a check for existing files:

if ( is_category() )
    $slug       = get_queried_object()->slug;
    $theme_path = "/images/slider_$slug.png";
    $file       = get_template_directory() . $theme_path;

    if ( file_exists( $file ) )
        echo '<img src="' 
            . get_template_directory_uri() . $theme_path 
            . '" alt="" height="200px" width="960px" />';
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.