您现在的位置是:首页 > 网站制作 > WordpressWordpress

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

杰帅2023-07-20【Wordpress】人已围观

简介熟悉Wordpress的朋友对SEO插件All in One SEO应该很熟悉,这是一个对SEO很有帮助的插件。但是这个插件如果处理noindex时不得当,会造成百度不收录的影响。而且一旦使用了这个插件一段时间后,一旦停止使用,会造成搜索引擎抓取的Meta大幅丢失,影响搜索排名。

熟悉Wordpress的朋友对SEO插件All in One SEO应该很熟悉,这是一个对SEO很有帮助的插件。但是这个插件如果处理noindex时不得当,会造成百度不收录的影响。而且一旦使用了这个插件一段时间后,一旦停止使用,会造成搜索引擎抓取的Meta大幅丢失,影响搜索排名。

那么有什么好的方法,既可以完美自定义关键字(keywords)和页面描述(description)呢?经过多方面的测试,完美的解决方法出炉。

第一步:打开主题的header.php文件,找到title标签,把下面的代码替换到你的主题中。当然,你也可以根据自己的要求作适当调整下面的代码。

<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 = "wordpress https://www.wpcn.net/描述";
$keywords = "wordpress https://www.wpcn.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; ?>" />

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

这样一来就大功告成了,以后就不要使用wordpress插件就可以实现网站seo优化了。

Tags:SEO   wordpress优化   wordpress教程

很赞哦! ()

文章评论

本站推荐

站点信息

  • 建站时间:2018-10-24
  • 网站程序:帝国CMS7.5
  • 主题模板《今夕何夕》
  • 文章统计1172篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们