Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I try to make custom taxonomies names to display with lowercase, but for some reason it doesnt work and show all taxonomy titles with big capital. Here is the code that i use:

    $genre = strtolower( strip_tags( get_the_term_list( $wp_query->post->ID, 'genre', '', ', ', '' ) ) );
if ( is_singular( array( 'dvd','vhs' ) )) {
echo '<meta name="description" content="'. get_the_title() .' is '. $genre .'." />';
}

Thank you all in advance :)

UPDATE

This is my whole code that I put in functions.php

    function test_seo() {


    $terms = get_the_terms( $post->ID, 'genre' );
    // var_dump($terms);
    $tnames = array();
    if (!is_wp_error($terms) && !empty($terms)) {
      foreach ($terms as $t) {
        $tnames[] = strtolower($t->name);
      }
      $genre = implode(', ',$tnames);
    }
    // var_dump($terms);


    if ( is_home() || is_front_page() || is_search() || is_tag() || is_tax() || is_page() ) {
        echo '<meta name="description" content="Test description" />';
    }

    elseif ( is_singular( array( 'dvd', 'vhs' ) )) {
        echo '<meta name="description" content="'. get_the_title() .' is '. $genre .'." />';
    }

}
add_action ( 'wp_head', 'test_seo');
share|improve this question

1 Answer 1

up vote 2 down vote accepted

What you are doing seems odd. You are creating and retrieving an HTML string only to strip out the HTML.

Try this:

$terms = get_the_terms( $post->ID, 'genre' );
// var_dump($terms);
$tnames = array();
if (!is_wp_error($terms) && !empty($terms)) {
  foreach ($terms as $t) {
    $tnames[] = strtolower($t->name);
  }
  $genre = implode(', ',$tnames);
}
// var_dump($terms);

You can un-comment the var_dumps to get an idea of what is happening. You can change the first parameter of implode to change the separators-- right now it uses a comma.

share|improve this answer
    
I try your code, but it's the same. All taxonomy names begin with a capital letter. –  Dido Kotsev Feb 2 '13 at 16:42
    
I ran my code and it does in fact generate an all lowercase string. I do not know what you are doing wrong but my code does in fact work. –  s_ha_dum Feb 2 '13 at 16:49
    
Wordpress latest version. I register taxonomy, no other plugins and stuff. In functions.php I put: $terms = get_the_terms( $post->ID, 'genre' ); // var_dump($terms); $tnames = array(); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $t) { $tnames[] = strtolower($t->name); } $genre = implode(', ',$tnames); } // var_dump($terms); if ( is_singular( array( 'dvd','vhs' ) )) { echo '<meta name="description" content="'. get_the_title() .' is '. $genre .'." />'; } It show on front - Indiana Jones is Action, Adventure –  Dido Kotsev Feb 2 '13 at 18:13
    
You should be getting errors if you put that in functions.php. $post isn't defined for one. Are you hooking this code to anything or just running it straight from functions.php? –  s_ha_dum Feb 2 '13 at 18:31
    
I update my first post with the whole code, that I put in functions.php. @s_ha_dum realy thank you for help :) –  Dido Kotsev Feb 2 '13 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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