说到网站的优化大家都知道wordpress这个程序虽然很好用但是它也是有缺点的,网站的优化不够可能导致网站访问缓慢,占用大量的主机资源和CPU这样不仅仅对网站不好而且对主机服务器也不好,今天简单主机(www.simplehost2.com)小编给大家介绍一下怎么优化头部标题。
使用文本工具新建一个title.php文件,把下列代码添加进去
2 |
if ( is_home() ) { ?><title><?php bloginfo( 'name' ); ?> | <?php bloginfo( 'description' ); ?> |
4 |
<?php if ( is_search() ) { ?><title>搜索结果 | <?php bloginfo( 'name' ); ?></title><?php } ?> |
5 |
<?php if ( is_single() ) { ?><title><?php echo trim(wp_title( '' ,0)); ?> | <?php bloginfo( 'name' ); ?></title><?php } ?> |
6 |
<?php if ( is_page() ) { ?><title><?php echo trim(wp_title( '' ,0)); ?> | <?php bloginfo( 'name' ); ?></title><?php } ?> |
7 |
<?php if ( is_category() ) { ?><title><?php single_cat_title(); ?> | <?php bloginfo( 'name' ); ?></title><?php } ?> |
8 |
<?php if ( is_month() ) { ?><title><?php the_time( 'F' ); ?> | <?php bloginfo( 'name' ); ?></title><?php } ?> |
9 |
<?php if (function_exists( 'is_tag' )) { if ( is_tag() ) { ?><title><?php single_tag_title( "" , true); ?> | <?php bloginfo( 'name' ); ?></title><?php } ?> <?php } ?> |
10 |
<?php if ( is_author() ) {?><title><?php wp_title( '' );?>发表的所有文章 | <?php bloginfo( 'name' ); ?></title><?php }?> |
12 |
if (!function_exists( 'utf8Substr' )) { |
13 |
function utf8Substr( $str , $from , $len ) |
15 |
return preg_replace( '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $from . '}' . |
16 |
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $len . '}).*#s' , |
22 |
if ( $post ->post_excerpt) { |
23 |
$description = $post ->post_excerpt; |
25 |
if (preg_match( '/<p>(.*)<\/p>/iU' ,trim( strip_tags ( $post ->post_content, "<p>" )), $result )){ |
27 |
$post_content = $result [ '1' ]; |
30 |
$post_content_r = explode ( "\n" ,trim( strip_tags ( $post ->post_content))); |
32 |
$post_content = $post_content_r [ '0' ]; |
35 |
$description = utf8Substr( $post_content ,0,220); |
39 |
$tags = wp_get_post_tags( $post ->ID); |
41 |
foreach ( $tags as $tag ) { |
43 |
$keywords = $keywords . $tag ->name . "," ; |
48 |
<?php if ( is_single() ) { ?> |
49 |
<meta name= "description" content= "<?php echo trim($description); ?>" /> |
50 |
<meta name= "keywords" content= "<?php echo rtrim($keywords,','); ?>" /> |
52 |
<?php if ( is_home() ) { ?> |
53 |
<meta name= "description" content= "首页描述" /> |
54 |
<meta name= "keywords" content= "首页关键字" /> |
把文件保存上传回php虚拟主机wordpress当前使用的主题文件夹里面,然后把主题里的header.php下载到本地,然后把下面的一段调用代码添加进去头部标题位置
<?php include(‘title.php’); ?>
添加完成后把文件上传回去,这样头部的优化就完成了。上述代码在wodpress 3.4.1版本中测试通过。

纯Linux环境、免备案【海外简单云】php空间,108元一年起。
【网上创业步骤】:
1 开通云主机、域名 2 建设官方网站 3 整体网站推广 … 成功见证 创业技能素质培训
更多有价值的内容:
简单主机官方网站 www.simplehost2.com
简单主机官方网店 store.simplehost2.com
简单主机官方相册 gallery.simplehost2.com
简单主机官方博客 blog.simplehost2.com
微信号:simplehost

扫一扫,了解更多…