Add Icons To Custom Taxonomies


Tags:

Dynamically adding icons to categories, tags and other taxonomy terms can be achieved by using these plugins:

WP Term Icons

and

Wp Term Meta

<?php
// Get the current queried object (category, tag, or custom taxonomy)
$queried_object = get_queried_object();

// Check if we are actually on a taxonomy term page to avoid errors
if ( is_tax() || is_category() || is_tag() ) {
    $term_id = $queried_object->term_id;

    // Get the icon for the current term_id
    $iconpic = get_term_meta( $term_id, 'icon', true );

    // Only echo the div if an icon has actually been set
    if ( ! empty( $iconpic ) ) {
        echo '<div class="dashicons ' . esc_attr( $iconpic ) . '"></div>';
    }
}
?>