Created
December 15, 2011 11:42
-
-
Save hzlzh/1480814 to your computer and use it in GitHub Desktop.
WordPress <Title> with categorys and tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<title><?php | |
// Logic of printing the <title> tag | |
global $page, $paged; | |
echo trim(wp_title( '', false, 'right' )); | |
global $post; | |
$post_tags = wp_get_post_tags($post->ID); | |
$numItems = count($post_tags); | |
$i = 0; | |
if ( !is_home() ){ | |
foreach ($post_tags as $post_tag) { | |
if($i == 0){ | |
echo '-'.$post_tag->name; | |
} | |
elseif ($i+1 == $numItems){ | |
echo $post_tag->name; | |
} | |
else{ | |
echo $post_tag->name.","; | |
} | |
$i++; | |
} | |
$post_cates = wp_get_post_categories($post->ID); | |
$cats = array(); | |
foreach ($post_cates as $c) { | |
$cat = get_category( $c,false); | |
echo '-'.$cat->name; | |
} | |
} | |
if ( !is_home() ) echo " | "; | |
bloginfo( 'name' ); | |
// Add the blog description only for home. | |
$site_description = get_bloginfo( 'description', 'display' ); | |
if ( $site_description && is_home() && !$paged ) | |
echo " | $site_description"; | |
// Paged format | |
if ( $paged >= 2 || $page >= 2 ) | |
echo ' - ' . sprintf( __( 'Page %s', 'dot-b' ), max( $paged, $page ) ); | |
?></title> | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment