WordPress自动添加关键词和描述的方法

WordPress自动添加关键词和描述seo

 登录自己的网站后台,然后点击编辑按钮,点击header.php文件,在<head>与</head>之间任意地方(一般加到<title></title>下面)加上如下代码:

<?php
if ( is_home ())
{
$description = "www.zhangfangzhou.cn,Discuz,WordPress,PHP,Red Hat,CentOS,Linux,Windows server 2008,Cisco,H3C,Network Engineering ";
$keywords = "Discuz,WordPress,PHP,Red Hat,CentOS,Linux,Windows server 2008,Cisco,H3C,Network Engineering ";
}
else if ( is_single ())
{
if ( $post->post_excerpt)
{
$description = $post->post_excerpt;
} else {
$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)
),0,220);
}
$keywords = "";
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords.$tag->name.","; }
} else if ( is_category()) {
$description = category_description();
}
?>
<meta name = "keywords" content="<?php echo $keywords; ?>" />
<meta name= "description" content="<?php echo $description; ?> "/ >

评论已关闭。