wordpress首页、页面、分类和文章加上description及keywords

发布于 2012-07-01 作者 [重庆SEO]

本文来自百度空间博客搬家

2007年开始使用的是 hi.baidu.com/udjy
后来百度空间强制升级为轻博客 hi.baidu.com/imnoco
2015年百度关闭了百度空间

wordpress首页、页面、分类和文章加上description及keywords,将下面的内容复制到wordress模版目录下的函数文件functions.php,然后在模版目录下的header.php对应位置添加<?php any_head_description(); ?><?php any_head_keywords(); ?>就行了.

 

add_action('wp_head', 'any_head_canonical');

function any_head_description( $output = '' ){
if( is_home() ){ $output = 'Sanxia Welding is the producer of inverter drawn arc stud welder, stud welding gun and shear connector. The products are used in steel structural construction and bridge project etc.'; }
if( is_page(array(42,'about-us','about us')) ){ $output = 'Saxia Welding established in 1995, located in China, is specialized in R&D, manufacturing, marketing and serving stud welding product and shear connector.'; }
if( is_page('contact') ){ $output = 'How to get in touch with Chongqing Sanxia Welding Machine Factory? There are following media: telephone, fax, email, address..'; }
if( is_category(13) ){ $output = 'Chongqing Sanxia Welding Machine Factory provides various kinds of inverter drawn arc stud welders, stud welding guns and shear connectors. It provides stud welding solution too.'; }
if( $output != '' ){ echo '<meta name="description" content="',$output,'"/>'."\n"; }
}


add_action('wp_head', 'description');

function any_head_keywords( $output = '' ){
if( is_home() ){ $output = 'stud welder,stud welding,welding machine,sanxia stud welder'; }
if( is_page(array(42,'about-us','about us')) ){ $output = 'stud welder,sanxia stud welder,stud welder factory,stud welding manufacturer'; }
if( is_page('contact') ){ $output = 'stud welder,contact,contact sanxia,contact sanxia stud welder,sanxia welding online'; }
if( is_category() ){$output =single_cat_title("", false).',stud welding products,sanxia stud welder' ; }
if( is_single() ){$output =wp_title("", false) .',china stud welder supply,stud welding products' ; }
if( $output != '' ){ echo '<meta name="keywords" content="',$output,'"/>'."\n"; }
}
add_action('wp_head', 'keywords');