Different titles for WordPress blog page and static front page
I was a little surprised when I realized that wp_title() doesn't return the page title for a static WordPress front page or the blog page. I don't like that, because I want at least the blog page to have a label. Something like... blog :-D or maybe news.
So I started to search a little and found no good solution. This post has a solution, but it's not optimal. I like to have a template that can be used across several blogs, so everything has to be dynamic. To make my version more dynamic Otto's comment on this thread was useful. So here it is:
<?php
if ( is_front_page() ) {
echo get_the_title(get_option('page_on_front')) . " - ";
} elseif ( is_home() ) {
echo get_the_title(get_option('page_for_posts')) . " - ";
}
bloginfo('name');
This is example is not a complete solution as it doesn't handle is_archive(), is_search() and friends and there's no HTML markup. But it should be easy to adapt the idea to your own template.Update: This is what I'm using now, it works on blogs that have a static frontpage and on blogs that don't have one.
<?php
if ( is_archive() ) {
echo 'Archives - ';
} elseif ( is_search() ) {
echo 'Search - ';
} elseif ( is_404() ) {
echo '404 - ';
} elseif ( is_front_page() && !is_home() ) {
echo get_the_title(get_option('page_on_front')) . " - ";
} elseif ( is_home() && !is_front_page() ) {
echo get_the_title(get_option('page_for_posts')) . " - ";
} else {
wp_title(' - ', true, 'right');
}
bloginfo('name');
?>
Most SEO plugins have a graphical interface for this
That may be true, but it's much better to build correctly SEOed themes to begin with. This post is intended for theme developers.