echo custom taxonomy slug (2 posts)

  1. digitalrenewal
    Posted 4 years ago #

    Can anyone tell me how to echo the custom taxonomy slug? I need it to define a class. I've tried this over and over in a million different ways and nada... Im plain exhausted.

  2. BeantownDesign
    Posted 3 years ago #

    Check this post:

    I used code from there to make a link that would print the name of the custom taxonomy slug and also add a class to the link which is the name of the slug.

    $taxonomy = 'your_taxonomy_name_here';
    $terms = get_the_terms( $post->ID , $taxonomy );
    if ( !empty( $terms ) ) :
    foreach ( $terms as $term ) {
    	$link = get_term_link( $term, $taxonomy );
    	if ( !is_wp_error( $link ) )
    		echo '<a href="example.com" rel="tag" class="' . $term->slug. '">' . $term->name . '</a>';

Topic Closed

This topic has been closed to new replies.

About this Topic