wordpress如何单独设置关键词(description)和描述(keywords),下面web建站小编给大家详细介绍一下具体实现代码!
在head
添加以下代码:
<?php $description = ''; $keywords = ''; if (is_home() || is_page()) { $description = "描述"; $keywords = "关键词"; } 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 = $description1 ? $description1 : $description2; $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 = category_description(); $keywords = single_cat_title('', false); } elseif (is_tag()){ $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; ?>" />
标签: wordpress建站, wordpress设置
上面是“wordpress怎么单独设置关键词(description)和描述(keywords)”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3693.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!