I'm using the following line to output an unordered list of taxonomies and their associated terms for a custom post type. The only problem with it is that a period gets added after the term.

wp_get_object_terms( $id, the_taxonomies( 'before=<ul><li>&sep=</li><li>&after=</li></ul>' ) );

Here's what it outputs:

<ul><li>Taxname: <a href='http://site.com/taxname/taxterm/'>Taxterm</a>.</li></ul>

Is there an argument I can add to wp_get_object_terms to remove the period?


wp_get_object_terms() isn't the problem. the_taxonomies() is doing the outputting; it doesn't return anything.

So, your code is equivalent to:

the_taxonomies( 'before=<ul><li>&sep=</li><li>&after=</li></ul>' );
wp_get_object_terms( $id, null );

Now, if you go to wp-includes/taxonomy.php you will find the dot in the_taxonomies() source.

To remove the dot, you need to add a filter:

function remove_the_dot($template) {
  return '%s: %l';
add_filter('taxonomy_template', 'remove_the_dot');

In case you're wondering, yes, this is an akward way of doing things.

In WP 3.1, you can modify the template simply by passing it as a parameter:

the_taxonomies( array(
  'before' => '<ul><li>',
  'sep' => '</li><li>',
  'after' => '</li></ul>',
  'template' => '%s: %l'
) );
  • Thanks. I'm assuming this line (in get_the_taxonomies) is causing it? $template = apply_filters('taxonomy_template', '%s: %l.'); If so, is there a good way to do this and avoid the periods? Feb 11 '11 at 20:42
  • Yes, it's just under your nose: the 'taxonomy_template' filter. See updated answer.
    – scribu
    Feb 11 '11 at 20:46

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.