Edited to add
Having looked at the source of wp_title()
, it looks like it already checks to see if you’re on a page, a single post, a category or tag archive page, a search results page, a 404, etc. So a lot of the code is redundant; you might be able to use something like this:
<title>
<?php
wp_title();
echo ' - ';
bloginfo( 'name' );
?>
</title>
…and get the results you want. (As to why your code snippet worked in the old theme: it’s possible the old theme was applying filters that the new one does not.)
Original answer
wp_title()
will always display the page title in your code, if one is found; then, since is_page()
is true
(on a page), that code block will also display the page title. (You’ll see the same issue on a single post, because there is_single()
will return true
.)
I’d suggest something like this:
<title>
<?php
// Shows the title of the page or post.
wp_title('');
// If it's an individual entry, you can customize the title here.
if (is_single()) {
echo ' - ';
}
// If it is a static page, displays the page title.
if (is_page()) {
echo ' - ';
}
// If it is a category, displays the category name.
if (is_category()) {
echo ' - ' . single_cat_title('', false);
}
// If it is a search, displays the search results.
if (is_search()) {
echo ' - Results for: ' . get_search_query();
}
// If it is a 404 error, it displays a custom message.
if (is_404()) {
echo ' - Page Not Found';
}
// At the end, always show the name of the blog.
bloginfo('name');
?>
</title>
…might work the way you’re expecting.