How to display custom taxo images in front-end
-
<?php
/**
* Display Custom Product Taxonomy [Brand] Images
* Install Plugin: Advanced Category and Custom Taxonomy Image BEFORE adding the following code to your child-theme functions
*/function fwuk_display_custom_taxo_images() {
global $product;
$tax = ‘brand’; // your custom taxonomy name$terms = get_terms( array( // Since 4.5.0
‘taxonomy’ => $tax,
‘hide_empty’ => false, // include empty terms
) );foreach( $terms as $term ) {
$taxonomy_img = get_taxonomy_image ($term->term_id);if (filter_var($taxonomy_img, FILTER_VALIDATE_URL)) { // check if there is valid image URL
echo ‘<div class=”taxo-image”>‘ . ‘‘ . ‘</div>’; // display taxo image
}
else { // if no valid image URL exists, display the taxo name instead
echo ‘<div class=”taxo-text”>‘ . $term->name . ‘</div>’;
}
}
}
add_action( ‘ hook into any of your theme action-hook locations ‘ , ‘fwuk_display_custom_taxo_images’ );?>
- The topic ‘How to display custom taxo images in front-end’ is closed to new replies.