纯代码替换All-in-One-SEO插件,实现WordPress SEO优化

2018-05-1014:53:21网站建设与开发 网站运营与SEO优化Comments2,993 views字数 1843阅读模式

All in One SEO是一个对wordpress SEO很有帮助的插件。但是这个插件如果处理noindex时不得当,会造成百度不收录的影响。而且一旦使用了这个插件一段时间后,一旦停止使用,会造成搜索引擎抓取的Meta大幅丢失,影响搜索排名。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

纯代码替换All-in-One-SEO插件,实现WordPress SEO优化文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

那么有什么好的方法,既可以完美自定义关键字(keywords)和页面描述(description)呢?经过多方面的测试,完美的解决方法出炉,在这里分享给所有学习wordpress使用教程的学员!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

第一步:打开主题的header.php文件,找到title标签,把下面的代码替换到你的主题中。当然,你也可以根据自己的要求作适当调整下面的代码。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;     wp_title( '-', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " – $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' – ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );
?></title>
<?php
if (is_home()){
$description = "学做网站论坛http://www.xuewangzhan.net/描述";
$keywords = "学做网站论坛http://www.xuewangzhan.net/关键词";}
elseif (is_single()) {
if ($post->post_excerpt) {
$description     = $post->post_excerpt;
} else {
$description = substr(strip_tags($post->post_content),0,220);
}
$description2 = mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 200, "…");
$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; ?>" />文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

第二步:进入你的wordpress后台,在编辑文章页面中,点击右上角[显示选项],选 择[摘要]。在[摘要]中输入这篇文章的页面描述(description)。标签则为关键字(keywords)。如果没有填写文章摘要,也可以自动抓 取文章前200个字作为Description。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

这样一来就大功告成了,以后就不要使用wordpress插件就可以实现网站seo优化了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3408.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/3408.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定