0

I'm using this code to get my term list, It works fine, but it also give me a white space before my TERM name, Any thoughts?

<span class="metaorange"><?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID,'genre','',',',''));
echo $terms_as_text; ?></span>
3
  • 1
    Can you show an example of the output?
    – birgire
    Jun 10, 2014 at 23:40
  • 1
    Can you verify this has nothing to do with the strip_tags?
    – Tom J Nowell
    Jun 11, 2014 at 0:19
  • Any progress on this question?
    – birgire
    Jun 15, 2014 at 10:39

1 Answer 1

0

I wonder if you got any term_links-genre filters that could be modifying your get_the_term_list() output?

Your code example should in general work as expected, but you might want to use the get_the_terms() function to better control the output to your own likings.

Here's a modifed version of the corresponding Codex example:

/**
 * Customized the term list
 *
 * @param  int    $pid
 * @param  string $tax
 * @param  string $seperator
 * @return string $out
 */

function custom_the_term_list( $pid = 0, $tax = 'category', $seperator = ',' )
{
    $out = '';
    $terms = get_the_terms( $pid, $tax );
    if ( $terms && ! is_wp_error( $terms ) ) :
        $list = array();
        foreach ( $terms as $term )    
        {
            $list[] = $term->name;
        }
        $out = join( $seperator, $list );
    endif;
    return $out;
}

Usage example:

printf( '<span class="metaorange">%s</span>',
    custom_the_term_list( get_the_id(), 'genre', ',' )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.