slug; } else { global $post; $cat = get_the_category( $post->ID ); $cat = $cat[0]->slug; } // The directory where the images reside $dir = get_stylesheet_directory() . '/images/custom-headers/' . $cat; if ( is_dir( $dir ) ){ // Get all images from the $dir above $images = glob( $dir . "/*.jpg" ); if ( $images ){ // Pick a random image $key = array_rand( $images ); // Make sure the resulting image is assigned to the $image variable $image = get_stylesheet_directory_uri() . "/images/custom-headers/$cat/" . basename( $images[$key] ); } } } return $image; } add_filter( 'graphene_header_image', 'graphene_custom_header_image' ); ?>