<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><?php
function taxo_icon_shortcode() {
ob_start();
$categories = get_the_category();
$separator = ' ';
$output = '';
?>
<div class="taxonomy-wrap">
<?php
if ( ! empty( $categories ) ) {
foreach( $categories as $category ) {
$id = get_term_meta( $category->term_id, 'icon_cat', true );
$image = wp_get_attachment_image( $id);
$output .= ' <a class="taxonomy-wrap__list" href="' . esc_url( get_category_link( $category->term_id ) ) . '">'.$image.' ' . esc_html( $category->name ) . '</a>' . $separator;
}
echo trim( $output, $separator );
}
?>
</div>
<?php
return ob_get_clean();
}
add_shortcode('taxoicon', 'taxo_icon_shortcode');
?> </pre>
Get image from taxonomy term using ACF
Tags