Smashing ebook #11 mastering wordpress advanced techniques 2011

Page 30

<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’s title.

Smashing eBook #11│Mastering WordPress │ 30


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.