Wordpress 首页、文章页等description、keywords设置

post_excerpt) {
			$description = $post->post_excerpt;
		}elseif($post->post_content){
			$description = strip_tags($post->post_content);
			$description = strip_shortcodes($post->post_content);
			$description = str_replace(array("\n", "\r", "\t"), '', $description);
			$description = preg_replace('/<.*?>/', '', $description);
			$description = mb_substr(strip_tags($description),0,300,'utf-8');
		}
	} else {
		$description = mb_substr(strip_tags($post->post_content),0,300,'utf-8');
	}
	//过滤
	$description = str_replace(array("\n", "\r", "\t"), '', $description);
	$description = preg_replace('/<.*?>/', '', $description);
	
	//$keywords = "";
	$tags = wp_get_post_tags($post->ID);
	foreach ($tags as $tag) {
		$keywords = $keywords . ",". $tag->name;
	}
	//去掉前后逗号
	$keywords= preg_replace('/^,/','',$keywords);
	$keywords = preg_replace('/,$/','',$keywords);
?>

将以上代码添加至模板中header.php文件,与之间即可。

你可能感兴趣的:(解决问题)