WordPress设置独立的Description 和 Keywords
将以下代码添加至WordPress主题header.php的<head></head>之间,最后用UTF-8编码另存为,否则中文会乱码:
<?php $description = ''; $keywords = ''; if (is_home() || is_page()) { // 将以下引号中的内容改成你的主页description $description = "露兜博客描述"; // 将以下引号中的内容改成你的主页keywords $keywords = "WordPress, 博客, 编程,php,ludou"; } elseif (is_single()) { $description1 = get_post_meta($post->ID, "description", true); $description2 = str_replace("\n","",mb_strimwidth(strip_tags($post->post_content), 0, 200, "…", 'utf-8')); // 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述 $description = $description1 ? $description1 : $description2; // 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词 $keywords = get_post_meta($post->ID, "keywords", true); if($keywords == '') { $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ", "; } $keywords = rtrim($keywords, ', '); } } elseif (is_category()) { // 分类的description可以到后台 - 文章 -分类目录,修改分类的描述 $description = category_description(); $keywords = single_cat_title('', false); } elseif (is_tag()){ // 标签的description可以到后台 - 文章 - 标签,修改标签的描述 $description = tag_description(); $keywords = single_tag_title('', false); } $description = trim(strip_tags($description)); $keywords = trim(strip_tags($keywords)); ?> <meta name="description" content="<?php echo $description; ?>" /> <meta name="keywords" content="<?php echo $keywords; ?>" />
相关推荐
Wordpress0 2020-09-27
bluehost 2020-09-15
maccarty 2020-08-03
86520993 2020-07-28
WordPress 2020-07-04
李维山 2020-06-21
GimmeS 2020-06-14
WordPress 2020-06-10
shayuchaor 2020-06-10
liwf 2020-06-02
疯狂老司机 2020-05-26
zcl 2020-05-12
timewind 2020-05-11
86520993 2020-05-04
Lophole 2020-04-29
fraternityjava 2020-04-23
84911835 2020-04-16
maccarty 2020-04-09
WordPress 2020-04-07