知更鸟wordpress主题不同页面添加自定义关键词和描述!

本篇文

知更鸟wordpress主题不同页面添加自定义关键词和描述!

章介绍了知更鸟begin主题,如何给不同页面添加自定义关键词和描述的方法,核心代码如下:
<?php
if (is_page()){
$title = $post->post_title.' - '.get_bloginfo('name');
if ($post->post_excerpt){ //如果有输入描述,就调用描述
$description = $post->post_excerpt;
} else { //否则调用页面内容前400字符作为描述
$description = substr(strip_tags($post->post_content),0,400);
}
$keywords = $post->post_title; //关键词等于标题,当然,你可以通过上面的代码也添加一个关键词字段
}
?>
在wordpress主题模板的header.php文件中调用即可,调用代码如下:
<meta name="keywords" content="<?php echo $keywords ?>" />
<meta name="description" content="<?php echo strip_tags(trim($description)); ?>" />
好了,今天木卢就给大家简单分享这个,希望能帮助到你。
留言与评论(共有 0 条评论)
   
验证码: