19 Jan 2008

I’ve searched long and hard trying to find a way to add the page name to the title tag dynamically to my WordPress blog page when I’m using WordPress as a CMS. I finally found the solution that I was able to understand at ‘Web Designer Wall.’ I changed his code a bit to suit my own needs and thought I’d paste the code here for anyone who may need it (and as a repository for me for future use).

The following PHP code should be placed between your title tags in the header.php file.

  1. < ?php
  2. if (is_home()) {
  3. echo 'News - Pop Stalin Design: Web Design With Standards'; wp_title('');
  4. } elseif (is_404()) {
  5. echo '404 Not Found'; echo ' - '; echo bloginfo('name');
  6. } elseif (is_category()) {
  7. echo 'Categories - '; echo wp_title(''); echo ' - '; echo bloginfo('name');
  8. } elseif (is_search()) {
  9. echo 'Search Results'; echo ' - '; echo bloginfo('name');
  10. } elseif ( is_day() || is_month() || is_year() ) {
  11. echo 'Archives - '; wp_title('');
  12. } else {
  13. echo wp_title(''); echo ' - '; echo bloginfo('name');
  14. }
  15. ?>

This code seems overly verbose to me but until I can figure out something more concise, this is what I’ll be using.

2 Comments

  1. No. 1 B2 01/19/08

    There is a good plugin if don’t want to touch your templates files : “All in One SEO”
    You can customize even each post and page title tags ^^

  2. No. 2 Jen 01/19/08

    Thanks for the tip!

Tell Me What You Think

About Me

My name’s Jen; I’m a cynical, sarcastic, ex-drummer who is fond of dark humor. I've held way too many factory & retail jobs but finally found my calling one Christmas holiday in a dark, musty basement. I am now a CSS & XHTML web standards looney and can be found daily—when I’m not at my Mac—at the local fair-trade coffee shop buying an iced-soy mocha no matter the temperature.

I am also the owner of Pop Stalin Design specializing in CSS & XHTML web design as well as custom WordPress themes.