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.

The wp_title-generated <title> in my custom taxonomy archive pages contains the singular taxonomy name with a colon. I can't figure out where this is coming from (or if it's default Wordpress behavior), and I'd like to remove it. For example, in the archive page for the term 'Vanilla' in a taxonomy called 'Flavors', the <title> is

Flavor: Vanilla | My Site Name

What I would like the title to be is simply

Vanilla | My site name

The code in header.php is this:

<title><?php wp_title('|', true, 'right'); ?></title>

There's only one function in functions.php that's hooked into wp_title, and it looks unrelated to the Taxonomy name. I can't figure out where this is coming from or how to remove it.

How can I remove this?

(The answer in How to remove parent taxonomy name from the title generated by wp_title()? is not generalizable to this, and I'm guessing there's a more direct way to do it.)

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Use wp_title filter to control output

function mamaduka_remove_tax_name( $title, $sep, $seplocation ) {
    if ( is_tax() ) {
        $term_title = single_term_title( '', false );

        // Determines position of separator
        if ( 'right' == $seplocation ) {
            $title = $term_title . " $sep ";
        } else {
            $title = " $sep " . $term_title;
        }
    }

    return $title;
}
add_filter( 'wp_title', 'mamaduka_remove_tax_name', 10, 3 );
share|improve this answer
    
This causes the page title to show up VanillaMy Site Name. It's missing the separator. Using add_filter( 'wp_title', 'mamaduka_remove_tax_name', 10, 3 ); –  supertrue Sep 21 '11 at 3:11
    
@supertrue edited my code now it should work properly –  Mamaduka Sep 21 '11 at 8:17
    
In case of archive pages using single_term_title might be suffice (it was for me at least :) ) –  Attila Fulop Mar 24 at 17:32
add comment

I'd recommend you use a SEO plugin to take control of all of your titles. WordPress SEO by Yoast is very good.

Or you could add a filter to wp_title to change the output.

<?php 
add_filter( 'wp_title', 'wpse29020_fix_title', 10, 3 );
function wpse29020_fix_title( $title, $sep, $seplocation )
{
    // If this isn't our flavors taxonomy, just return the title
    if( ! is_tax( 'flavors' ) ) return $title;

    // Get the term
    $obj = get_queried_object();

    // Get the terms name
    $name = sanitize_term_field( 'name', $obj->name, $obj->term_id, 'flavors', 'display' );

    // construct the title
    $title = $name . " $sep " . bloginfo( 'name' );
    return $title;
}
share|improve this answer
    
This code changes my titles to My Site NameVanilla | My Site Name. Do you have any idea why this might be happening? (See also my comment on Mamaduka's answer.) –  supertrue Sep 21 '11 at 3:42
    
Probably something with your theme. Make sure it's just <title><?php wp_title(''); ?></title>. Also, you should follow Mamaduka's answer: more concise and a better use of the WP api(s). –  chrisguitarguy Sep 21 '11 at 13:32
add comment

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.