wordpress标题优化定制

根据mystique主题中的标题函数修改。

使用时在header.php中修改title标签内容为

<title><?php fungo_title(); ?></title>

即可。

显示形式为

博客主页显示为 博客名称 博客描述
博客文章页面为 文章标题 分类名 博客名
tag显示为 tag 博客名
分类显示为 分类名称 博客名

$separator可以自己定义。

function fungo_title($separator = &#8216; &#124; &#8216;){

global $wp_query;

if (is\_front\_page() && is_home()):

$doctitle = get\_bloginfo(&#8216;name&#8217;).$separator.get\_bloginfo(&#8216;description&#8217;);

elseif (is\_home() || is\_singular()):

$id = $wp\_query->get\_queried\_object\_id();

$doctitle = get\_post\_meta($id, &#8216;title&#8217;, true);

$category = get\_the\_category();
     
if($category[0]->cat_name)

$doctitle = (!$doctitle && is\_front\_page()) ? get\_bloginfo(&#8216;name&#8217;).$separator.get\_bloginfo(&#8216;description&#8217;) : get\_post\_field(&#8216;post\_title&#8217;, $id).$separator.$category[0]->cat\_name.$separator.get_bloginfo(&#8216;name&#8217;);
     
else
     
$doctitle = (!$doctitle && is\_front\_page()) ? get\_bloginfo(&#8216;name&#8217;).$separator.get\_bloginfo(&#8216;description&#8217;) : get\_post\_field(&#8216;post\_title&#8217;, $id).$separator.get\_bloginfo(&#8216;name&#8217;);

elseif (is_archive()):

if (is\_category() || is\_tag() || is_tax()):

$term = $wp\_query->get\_queried_object();

$doctitle = $term->name;

elseif (is_author()):

$doctitle = get\_the\_author\_meta(&#8216;display\_name&#8217;, get\_query\_var(&#8216;author&#8217;));

elseif (is_date()):

if (is_day())

$doctitle = sprintf(\_\_(&#8216;Archive for %s&#8217;, "mystique"), get\_the\_time(\_\_(&#8216;F jS, Y&#8217;, "mystique")));

elseif (get\_query\_var(&#8216;w&#8217;))

$doctitle = sprintf(\_\_(&#8216;Archive for week %1$s of %2$s&#8217;, "mystique"), get\_the\_time(\_\_(&#8216;W&#8217;, "mystique")), get\_the\_time(__(&#8216;Y&#8217;, "mystique")));

elseif (is_month())

$doctitle = sprintf(_\_(&#8216;Archive for %s&#8217;, "mystique"), single\_month_title(&#8216; &#8216;, false));

elseif (is_year())

$doctitle = sprintf(\_\_(&#8216;Archive for year %s&#8217;, "mystique"), get\_the\_time(\_\_(&#8216;Y&#8217;, "mystique")));

endif;

elseif (is_search()):

$doctitle = sprintf(_\_(&#8216;Search results for %s&#8217;, "mystique"),&#8217;&quot;&#8217;.esc\_attr(get\_search\_query()).&#8217;&quot;&#8217;);

elseif (is_404()):

$doctitle = __(&#8216;404 Not Found&#8217;, "mystique");

endif;

/\* If paged. \*/

if ((($page = $wp\_query->get(&#8216;paged&#8217;)) || ($page = $wp\_query->get(&#8216;page&#8217;))) && $page > 1)

$doctitle .= $separator.sprintf(__(&#8216;Page %s&#8217;, "mystique"), $page);

/\* if comment page&#8230; \*/

if (get\_query\_var(&#8216;cpage&#8217;))

$doctitle .= $separator.sprintf(_\_(&#8216;Comment Page %s&#8217;, "mystique"), get\_query_var(&#8216;cpage&#8217;));

if (!(is\_front\_page() || is\_home() || is\_singular())):
    
//add blog title here by fungo
    
$doctitle .=$separator.get_bloginfo(&#8216;name&#8217;);
    
endif;

/\* Apply the wp_title filters so we&#8217;re compatible with plugins. \*/

$doctitle = apply\_filters(&#8216;wp\_title&#8217;, $doctitle, $separator, &#8221;);

echo $doctitle;

}
  
孤独的北山羊 /
Published under (CC) BY-NC-SA in categories wordpress  tagged with WordPress  标题定制