wordpress SEO 设置方法
<?php if ( is_home() ) { ?><title><?php bloginfo('name'); ?> | <?php bloginfo('description'); ?></title><?php } ?> <?php if ( is_search() ) { ?><title>搜索结果 | <?php bloginfo('name'); ?></title><?php } ?> <?php if ( is_single() ) { ?><title><?php echo trim(wp_title('',0)); ?> | <?php bloginfo('name'); ?></title><?php } ?> <?php if ( is_page() ) { ?><title><?php echo trim(wp_title('',0)); ?> | <?php bloginfo('name'); ?></title><?php } ?> <?php if ( is_category() ) { ?><title><?php single_cat_title(); ?> | <?php bloginfo('name'); ?></title><?php } ?> <?php if ( is_month() ) { ?><title><?php the_time('F'); ?> | <?php bloginfo('name'); ?></title><?php } ?> <?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><title><?php single_tag_title("", true); ?> | <?php bloginfo('name'); ?></title><?php } ?> <?php } ?> <?php if (!function_exists('utf8Substr')) { function utf8Substr($str, $from, $len) { return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',$str); } } if ( is_single() ){ if ($post->post_excerpt) { $description = $post->post_excerpt; } else { if(preg_match('/<p>(.*)<\/p>/iU',trim(strip_tags($post->post_content,"<p>")),$result)){ $post_content = $result['1']; } else { $post_content_r = explode("\n",trim(strip_tags($post->post_content))); $post_content = $post_content_r['0']; } $description = utf8Substr($post_content,0,220); } $keywords = ""; $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ","; } } ?> <?php echo "\n"; ?> <?php if ( is_single() ) { ?> <meta name="description" content="<?php echo trim($description); ?>" /> <meta name="keywords" content="<?php echo rtrim($keywords,','); ?>" /> <?php } ?> <?php if ( is_home() ) { ?> <meta name="description" content="<?php echo get_option('swt_description'); ?>" /> <meta name="keywords" content="<?php echo get_option('swt_keywords'); ?>" /> <?php } ?>以上是seo.php代码,在heard.php <meta>中间写入:<?php include('includes/seo.php'); ?> 即可。
最新日志
最新碎语
- 此生不悔入华夏,来世还做中国人!
2019-09-30 21:39
- 物来顺应,未来不迎,当事不杂,季过不恋.
2019-08-14 22:36
- 砍柴的和放牛的聊天,聊到最后,人家牛吃饱了,你柴嗝屁了.
2019-06-19 16:51
- 抖音寻夫若为真,我愿剃度永为僧
2019-06-02 00:27
- 如果已婚,请穿好你的衣服,这是对你丈夫的尊重,如果未婚,也穿好衣服,这是对你自己的尊重,如果是出来卖的,请说明价格和服务,这是对消费者的尊重,如果不卖只是为了博眼球,请你再穿少一点,我看的不够清楚。
2019-04-25 08:52