<?php
if (is_home()) {
$description = "自己的站点描述";
$keywords = "WordPress, 博客";
} elseif (is_single()) {
if ($post->post_excerpt) {
$description = $post->post_excerpt;
} else {
$description = substr(strip_tags($post->post_content), 0, 220);
}
$keywords = "";
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag) {
$keywords .= $tag->name . ", ";
}
}
?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />
使用方法:
将这段代码添加到主题的header.php页面,<title>***</title>下方保存即可。