WordPress.org

Ready to get started?Download WordPress

Forums

echo custom taxonomy slug (2 posts)

  1. digitalrenewal
    Member
    Posted 3 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
    Member
    Posted 2 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.

    <?php
    $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>';
    }
    endif;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic