[wp-hackers] Problem with custom title tags

Kim Parsell kparsell-wp at kpdesign.net
Wed Feb 18 19:32:25 GMT 2009


I am trying to set up custom title tags using conditional tags, and have 
run into a problem with a couple of them. Here is the code that I am 
using in header.php of the theme:

--------------------------------------------------
<title><?php if (is_front_page()) { ?><?php bloginfo('name'); ?> - <?php 
echo bloginfo ('description'); } ?>
<?php if (is_page()) { ?> <?php bloginfo('name'); ?> <?php wp_title(' | 
', true, 'left'); } ?>
<?php if (is_home()) { ?><?php bloginfo('name'); ?> | Blog Posts<?php } ?>
<?php if (is_404()) { ?><?php bloginfo('name'); ?> | Error 404 - Not 
Found<?php } ?>
<?php if (is_category()) { ?><?php bloginfo('name'); ?> | <?php 
single_cat_title(); } ?>
<?php if (is_single()) { ?><?php bloginfo('name'); ?> | <?php 
single_cat_title(); ?>: <?php the_title(); } ?>
<?php if (is_day()) { ?><?php bloginfo('name'); ?> | Archives for <?php 
the_time('F j, Y'); } ?>
<?php if (is_month()) { ?><?php bloginfo('name'); ?> | Archives for 
<?php the_time('F Y'); } ?>
<?php if (is_year()) { ?><?php bloginfo('name'); ?> | Archives for <?php 
the_time('Y'); } ?>
<?php if (is_search()) { ?><?php bloginfo('name'); ?> | Search Results 
for <?php the_search_query(); } ?></title>
-------------------------------------------------

The first one that I am having problems with is:

<?php if (is_front_page()) { ?><?php bloginfo('name'); ?> - <?php echo 
bloginfo ('description'); } ?>

This returns <title>Blog Name - Service, Support, Solutions Blog Name 
</title>. The blog name is being repeated after the description (is this 
a bug or intended behavior?).

The other one I am having problems with is:

<?php if (is_single()) { ?><?php bloginfo('name'); ?> | <?php 
single_cat_title(); ?>: <?php the_title(); } ?>

This code returns <title>Blog Name | : Who We Are</title> - note that 
the Category title (single_cat_title) is missing.

<?php if (is_category()) { ?><?php bloginfo('name'); ?> | <?php 
single_cat_title(); } ?> returns <title>Blog Name | Company 
News</title>, so single_cat_title() works properly there, but not in the 
above code for is_single().

All the rest of them are returning the correct page title results.

I usually use the SEO Title Tag plugin to set all of the page titles, 
but the client is hosted on GoDaddy and the server is already slow, so I 
wanted to do this without using a plugin (trying to keep those to a 
minimum).

These issues are occurring with a fresh 2.7.1 install.

I've been through both the Codex and search results on Google, and am 
not finding the answers.

Thanks in advance - any help would be most appreciated!

Kim



More information about the wp-hackers mailing list