I’m working on a site that uses a CPT taxonomy as well as Blog Post taxonomies (Practice Areas Types and Category). What I’m trying to do is create a conditional output that if the CPT Posts and Blog Posts fall within a condition based upon the taxonomy name, it will output an image. However, I’m encountering two issues:
(1) The CPT Posts are connected to MULTIPLE CPT taxonomies, and the Blog Posts are related to multiple Blog Post taxonomies.
(2) Most of the CPT taxonomies have the same names as the Blog Post taxonomies (please don’t ask why–I did not develop the site), and many of the taxonomy slugs are the same.
(3) The conditional code I’m creating, however, will either post two images instead of one based upon the fact that both the CPT Posts and the Blog Posts are using multiple taxonomies, and I only want ONE image to post based upon the taxonomy that is Priority. If the condition doesn’t apply to any of the post taxonomies, then the ‘else :’ kicks in with a default image.
(4) I need the correct image to post if the user visits the Blog Taxonomy archive and the CPT Taxonomy page as well.
Here is what I have thus far that is working for CPT Posts that are only assigned to ONE single taxonomy…somewhat:
<?php
$terms = get_the_terms( get_the_ID(), array ( 'practice-areas-types', 'category' ) );
if ( !empty($terms) && !is_wp_error($terms) ) :
foreach ( $terms as $category ) :
$term_name = $category->name;
if ( $term_name == 'Data Breaches' ) :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2025/arnold-data-breach-attorneys.avif" alt="Sacramento Data Breaches Lawyer Arnold Law Firm"></a>';
break;
elseif ( $term_name == 'Personal Injury' || 'Car Accidents' || 'Motorcycle Accidents' || 'Truck Accidents' || 'Airplane Accidents' || 'Boating Accidents' || 'Burn Injuries' || 'Catastrophic Injuries' || 'Defective Medical Products' || 'Dog Bites' || 'Drunk Driving Injuries' || 'Food Poisoning' || 'Hit and Run Accidents' || 'Paralysis' || 'Premises Liabilty' || 'Spinal Cord Injuries' || 'Traumatic Brain Injuries' || 'Wrongful Death' || 'Train Accidents' || 'Shoulder Injuries' || 'Broken Bones' || 'Wildfires' || 'Rideshare Accidents' || 'Whiplash Injuries') :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2025/arnold-accident-injury-attorneys.avif" alt="Sacramento Personal Injury Lawyer Arnold Law Firm"></a>';
break;
elseif ( $term_name == 'Employment Law' ) :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2025/arnold-employment-attorneys.avif" alt="Sacramento Employment Lawyer Arnold Law Firm"></a>';
break;
elseif ( $term_name == 'Class Action' || 'Product Safety' || 'Dangerous Drugs' || 'Data Breach' ) :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2025/arnold-class-action-attorneys.avif" alt="Sacramento Class Action Attorneys Arnold Law Firm"></a>';
break;
else :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2017/arnold-logo-new.svg" alt="Sacramento injury Lawyer Arnold Law Firm"></a>';
endif;
endforeach;
else :
echo '<a href="/"><img id="site-logo" class="img-responsive" src="' . esc_url(get_template_directory_uri()) . '/assets/images/2017/arnold-logo-new.svg" alt="Sacramento injury Lawyer Arnold Law Firm"></a>';
endif;
?>
Thank you for taking a look, and I appreciate any help!