Skip to content

Instantly share code, notes, and snippets.

@rali14
Last active August 14, 2023 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rali14/c9c5e9ea6d2ff057c50559a7dd5f23a1 to your computer and use it in GitHub Desktop.
Save rali14/c9c5e9ea6d2ff057c50559a7dd5f23a1 to your computer and use it in GitHub Desktop.
Shortcode to Display Course Categories
function ld_display_course_categories ($atts) {
$terms = get_the_terms( get_the_ID() , 'ld_course_category' );
if (!$terms) {
// No terms, so just quit.
return false;
}
$categories= "";
foreach ( $terms as $term ) {
$categories .= ", " . "<a href='" . get_term_link($term) . "'>" . $term->name ."</a>";
}
return "<span class='ld-course-categories'>" . trim($categories, ",") . "</span>";
}
add_shortcode( 'ld_course_categories', 'ld_display_course_categories' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment