Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created September 3, 2021 23:06
Show Gist options
  • Select an option

  • Save wpexplorer/6d0ae9b369272135cc0f6d26c2081159 to your computer and use it in GitHub Desktop.

Select an option

Save wpexplorer/6d0ae9b369272135cc0f6d26c2081159 to your computer and use it in GitHub Desktop.
Category Icon Overlay | Total WP Theme
<?php
defined( 'ABSPATH' ) || exit;
if ( 'outside_link' !== $position ) {
return;
}
$taxonomy = wpex_get_post_primary_taxonomy(); // NOTE, if you know the taxonomy name you want to use, use that!!
$term_id = wpex_get_first_term_id( get_post(), $taxonomy );
if ( ! $term_id ) {
return; // no category
}
$term = get_term( $term_id, $taxonomy );
if ( ! $term || ! is_wp_error( $term ) ) {
return;
}
$term_slug = $term->slug;
// Get your icon based on the slug.
// IMPORTANT - make sure the path matches the folder where your icons are stored!!!
$icon = locate_template( 'category-icons/' . $term_slug . '.svg', false );
if ( $icon ) {
return; // no icon found.
}
?>
<div class="theme-overlay markoning-category-tag-overlay"><?php echo file_get_contents( $icon ); ?></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment