很多初学者使用wordpress建站,使用的主题没有自带关键词(keywords)和描述(description),那么我们应该如何设置呢?
一:发布文章的时候,没有自动生成关键词,我们可以使用 “WP AutoTags” 这款插件来辅助我们,搜索安装好之后,发布文章的时候可以自动帮我们生成关键词。
二:自动生成关键词之后,首页和文章也还是没有自动引入,这个时候我们需要在主题文件编辑器里面,找到头部文件,在title的后面或者前面增加以下代码保存,这个时候你发布文章的时候,自动生成了标签,也会自动引入到文章页面了。
代码如下:
<?php if (is_home()){ $keywords = “这是你网站首页的关键词”; $description = “这是你网站首页的描述”;} elseif (is_single()){ $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, ‘, ‘); } $description = get_post_meta($post->ID, “description”, true); if($description == “”){ if($post->post_excerpt){ $description = $post->post_excerpt; }else{ $description = mb_strimwidth(strip_tags(apply_filters(‘the_content’,$post->post_content)),0,200); } }} elseif (is_page()){ $keywords = get_post_meta($post->ID, “keywords”, true); $description = get_post_meta($post->ID, “description”, true);} elseif (is_category()){ $keywords = single_cat_title(”, false); $description = category_description();} elseif (is_tag()){ $keywords = single_tag_title(”, false); $description = tag_description();} $keywords = trim(strip_tags($keywords)); $description = trim(strip_tags($description));?><meta name=”keywords” content=”<?php echo $keywords; ?>” /> <?php echo “\n”; ?> <meta name=”description” content=”<?php echo $description; ?>” />
三:以上说的是我自己本人在用的方法,当然也可以用其他插件实现,比如这款“Smart SEO Tool” 不需要插入代码就可以实现,
声明:该文观点仅代表作者本人,《前端技术分享网》系信息发布平台,前端技术分享网仅提供信息存储空间服务。发布者:果壳日志,转载请注明出处:https://www.xin12123.com/n/383.html