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.

Is there any way to overwrite a <head><title>Category title</title></head> tag?

Let's say i have a "Videos" category, when user point's his browser to www.website.com/category/videos/, the page title (this one in head section) is Videos. What i need to do is to somehow overwrite it to display Archive string (without changing this category title), it can be hardcoded in some way cause i have just this one single category.

Any help would be appreciated.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You can use the wp_title filter to modify the output of the wp_title function.

quick example based on the example from Codex:

add_filter( 'wp_title', 'wpa66574_title_filter', 10, 3 );

function wpa66574_title_filter( $title, $sep, $seplocation ) {
    // account for $seplocation
    $left_sep = ( $seplocation != 'right' ? ' ' . $sep . ' ' : '' );
    $right_sep = ( $seplocation != 'right' ? '' : ' ' . $sep . ' ' );

    $page_type = '';

    // get special page type (if any)
    if( is_category( 'videos' ) ) $page_type = $left_sep . 'Archive' . $right_sep;

    // get the page number
    if( get_query_var( 'paged' ) ) $page_num = $left_sep. get_query_var( 'paged' ) . $right_sep; // on index
    elseif( get_query_var( 'page' ) ) $page_num = $left_sep . get_query_var( 'page' ) . $right_sep; // on single
    else $page_num = '';

    // concoct and return title
    return $page_type . $title . $page_num;
}
share|improve this answer
add comment

Depending on your theme, in the header.php template, just find the line with the <title> tag, something like this:

<title><?php wp_title( '' ); ?></title>

Then check which page type you're on and edit as necessary:

<title>
    <?php if ( is_category( 'video' ) ) echo 'Archive: '; ?>
    <?php wp_title( '' ); ?>
</title>

Keep in mind that themes and plugins mess with the <title> tag all the time, so you might run into conflicts. If you don't want to mess with your theme directly, try a plugin that can handle this, like WordPress SEO.

share|improve this answer
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.