<title> <?php if (is_home () ) { bloginfo('name'); } elseif ( is_category() ) { single_cat_title(); echo ' - ' ; bloginfo('name'); } elseif (is_single() ) { $customField = get_post_custom_values("title"); if (isset($customField[0])) { echo $customField[0]; } else { single_post_title(); } } elseif (is_page() ) { bloginfo('name'); echo ': '; single_post_title(); } else { wp_title('',true); } ?> </title>
Then, if you want to define a custom title tag, simply create a custom field called title, and enter your custom title as a value. Code explanation. With this code, I have used lots of template tags to generate a custom <title> tag for each kind of post: home page, page, category page and individual posts. If the active post is an individual post, the code looks for a custom field called title. If one is found, its value is displayed as the title. Otherwise, the code uses the standard single_post_title() function to generate the postâ&#x20AC;&#x2122;s title.
Smashing eBook #11â&#x201D;&#x201A;Mastering WordPress â&#x201D;&#x201A; 30