纯代码替换All-in-One-SEO插件,实现WordPress SEO优化
熟悉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优化了。
标签 : SEO , wordpress优化 , wordpress教程
本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!
本文链接: http://www.wpcn.net/945.html
- wp_list_comments()使用回调函数自定义评论…
- WordPress函数:comment_form() 让你的 Word…
- WordPress过滤器(Filters):apply_filters和…
- WordPress函数:comments_template(加载评…
- WordPress函数:comment_form( )个性化评论…
- 无处不在的WordPress的主循环
- WordPress 函数do_action()详解和应用举例
- WordPress函数:add_menu_page()后台添加顶…
- WordPress函数:add_theme_page()后台添加设…
- WordPress 函数:get_template_part()调用你…
- WordPress函数:load_theme_textdomain()(…
- WordPress 3D旋转彩色标签云
- WordPress文本小工具运行PHP
- WordPress无插件实现主题彩色标签云的N种方…
- WordPress函数:wp_tag_cloud(标签云)详解和…
- WordPress函数:register post type (自定义…
- WordPress使用register_post_type 函数创建…
- WordPress函数:add_meta_box(自定义添加Me…
- WordPress函数:get_permalink()获取文章页…
- WordPress使用query_posts()函数WP_Query类…
- WordPress调用置顶文章显示置顶数量的三种方…
- WordPress分类列表函数:wp_list_categories…
- WordPress友情链接函数wp_list_bookmarks使…
- WordPress判断文章分类函数in_category和is_…