//* Add category icons to the entry header
add_action( 'genesis_entry_header', 'dk_add_category_icons' );
function dk_add_category_icons() {
if ( is_single() ) {
$post_id = get_the_ID();
$categories = wp_get_object_terms( $post_id, 'category' );
$html = '<div class="category-icon-wrapper">';
foreach ( $categories as $cat ) {
$html .= dk_get_category_html( $cat );
}
echo $html . '</div>';
}
}
//* If a category icon has been assigned, construct the image HTML and return it
function dk_get_category_html( $category ) {
$icon_url = get_field( 'category_icon', $category );
if ( $icon_url ) {
$link = get_category_link( $category );
return '<a href="' . $link . '"><img src="' . $icon_url . '" alt="' . $category->name . '" /></a>';
}
return '';
}