我在我的header.php
:
<title>
<?php
if(is_front_page())
echo "Front Page Title";
else if(is_404())
echo "Page Not Found";
else
the_title();
echo \' | \'.get_bloginfo(\'name\');
?>
</title>
退房
Conditional Tags 了解更多信息。
作为函数():
functions.php
function setTitle(){
global $post;
$title = get_the_title();
$term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) );
if(is_tax())
$title = $term->name;
else if(is_search())
$title = "Search";
else if(is_404())
$title = "Page Not Found";
if(is_singular(\'customCPT\')){
$terms = get_the_terms( $post->ID, \'customCPT\' );
$term = array_pop($terms);
$title = $term->name.\' \'.$title;
}
echo $title.\' | \'.get_bloginfo(\'name\');
}
然后在你的
header.php
<title><?php setTitle(); ?></title>