Default / 默认 · 8月 31, 2021

“2013年1月10日wordpress性能优化日志”

内容纲要
记录下最近对wordpress做的一些优化. 插件方面 BWP Google XML Sitemaps: 绝对好用的google sitemap插件,这个插件能够把sitemap分成好多个进行提交,自己只有提交一个目录页面就好.因为分页所以能够很好的应对文章数目恨庞大的情况,有效预防内存吃紧. Permalink Finder: 一直用,页面找不到时候自动搜索匹配页面,从其他博客搬家时候很方便,我就是从blogger搬家的时候开始用的. Platinum SEO Pack: seo插件功能很全,相对占有资源少些. Search & Replace: 执行sql批量替换文本之类的,偶尔启用下,也可以直接去sql. SEO Friendly Images: 给图片添加title和alt,已用代码替换. Super Switch: 关闭自动保存之类的. Web Ninja Auto Tagging System: 自动获取Tags,懒人必备(中文毋庸). WordPress MU Domain Mapping: 启用多博客,域名映射. WP-UTF8-Excerpt: 截取摘要,已用代码替换. WP Keyword Link: tags自动内链,相关文章(由于相关文章严重拖累页面速度,已采用Yet Another Related Posts Plugin代替). WP No External Links: 外链转内链,已采用代码替换. WP Super Cache: 超级缓存,配置了多博客下使用. WP Widget Cache: 缓存widget,配合WP Super Cache进一步减少资源消耗. Yet Another Related Posts Plugin: 相关文章插件,功能很强大,自定义模板自动调取文章第一服图片作为图片. 以下是用通过代码修改来减少资源消耗 修改Theme Functions (functions.php) 禁用评论功能,实在受不了垃圾评论索性禁用使用第三方评论,建议使用facebook或者http://disqus.com/ 墙内用户自己搜索友言之类的社会化评论.disable的插件般很好的能够融合到wordpress之中,facebook也有个facebook seo,也不错.另外说句google已经能爬取facebook评论内容,虽然是框架. function __disable_feature($data) { return false; } add_filter(‘comments_number’, ‘__disable_feature’); add_filter(‘comments_open’, ‘__disable_feature’); 外链转内链加nofollow,我这里没做跳转直接是用了adfly的跳转,呵呵能够从adfly获取一点收入. function fb_filter_query( $query, $error = true ) { if ( is_search() ) { $query->is_search = false; $query->query_vars[s] = false; $query->query[s] = false; // to error if ( $error == true ) $query->is_404 = true; } } add_filter(‘the_content’,’the_content_nofollow’,99); function the_content_nofollow($content){ preg_match_all(‘/href=”(.*?)”/’,$content,$matches); if($matches){ foreach($matches[1] as $val){ if( strpos($val,home_url())===false ) $content=str_replace(“href=\”$val\””, “href=\”http://adf.ly/123456/$val\” rel=\”external nofollow\” “,$content); } } return $content; } 截取内容中第一张图片函数 输出把 <span class=”post-thumbnail-default”> <img src=”<?php echo catch_that_image(); ?>” alt=”<?php the_title(); ?>” title=”<?php the_title(); ?>” class=”post-thumbnails”/></span>添加到 loop.php等地 以下是函数 function catch_that_image() { global $post, $posts; ob_start(); ob_end_clean(); preg_match(‘/<img\s[^<>]*?src=[\’\”]([^\’\”<>]+?)[\’\”][^<>]*?>/i’, $post->post_content, $matche); if($matche[1]) return $matche[1]; //否则取默认图片 return ‘https://lh4.ggpht.com/GQCST-Z7pIdNOftpdrS1Qele0eVrm160qtdOYVQNd30-2RLz8fEwSxSIGaMm_VbgMg=w705’; } 自动图片添加title和alt function photo_alt($c) { global $post;//全局量 $title = $post->post_title;//文章标题 $s = array(‘/src=”(.+?.(jpg|bmp|png|jepg|gif))”/i’ => ‘src=”$1″ alt=”‘.$title.'” title=”‘.$title.'”‘); foreach($s as $p => $r){ $c = preg_replace($p,$r,$c); } return $c; } add_filter( ‘the_content’, ‘photo_alt’ ); 以下是移除head里很多没用的标记,feed你可以自己写到header.php里 remove_action( ‘wp_head’, ‘wp_generator’ ); remove_action( ‘wp_head’, ‘rsd_link’ ); remove_action( ‘wp_head’, ‘wlwmanifest_link’ ); remove_action( ‘wp_head’, ‘index_rel_link’ ); remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 ); remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 ); remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 ); remove_action( ‘wp_head’, ‘rel_canonical’ ); remove_action( ‘wp_head’, ‘feed_links’, 2 ); remove_action( ‘wp_head’, ‘feed_links_extra’, 3 ); 最后就是把主题里的很多乱七八糟的东西删删此处就不写了 ok以上就是最近做的些优化,只希望wordpress能够跑的更快些. 对了还有自定义个yarpp模板yarpp-template-terrychan.php <?php /* YARPP Template: yarpp-template-Terrychan.php Author: mitcho (Michael Yoshitaka Erlewine) Description: A simple example YARPP template. */ ?> <h3>Related <?php the_title(); ?> Apps</h3> <div class=”yarpp-thumbnails-horizontal”> <?php if (have_posts()):?> <?php while (have_posts()) : the_post(); ?> <a class=’yarpp-thumbnail’ href=”<?php the_permalink() ?>” rel=”bookmark”> <span class=”yarpp-thumbnail-default”><img src=”<?php echo catch_that_image(); ?>” alt=”<?php the_title(); ?>” title=”<?php the_title(); ?>” class=”yarpp-post-thumbnails”/></span><span class=”yarpp-thumbnail-title”><?php the_title(); ?></span></a><!– (<?php the_score(); ?>)–> <?php endwhile; ?> </div> <?php else: ?> <p>No related Apps.</p> <?php endif; ?> 以下是css,自己添加到主题css文件里,其实使用的是 yarpp的缩略图css稍微改了些 /***yarpp***/ .yarpp-thumbnails-horizontal .yarpp-thumbnail,.yarpp-thumbnail-default,.yarpp-thumbnail-title{display:inline-block;*display:inline;}.yarpp-thumbnails-horizontal .yarpp-thumbnail{border:1px solid rgba(127,127,127,0.1);width:130px;height:180px;margin:5px;margin-left:0px;vertical-align:top;}.yarpp-thumbnail>img,.yarpp-thumbnail-default{width:120px;height:120px;margin:5px;}.yarpp-thumbnails-horizontal .yarpp-thumbnail>img,.yarpp-thumbnails-horizontal .yarpp-thumbnail-default{display:block;}.yarpp-thumbnails-horizontal .yarpp-thumbnail-title{margin:2px;margin-top:0px;width:120px;text-decoration:inherit;overflow:hidden;}.yarpp-thumbnail-default{overflow:hidden;}.yarpp-thumbnail-default>img{min-height:120px;min-width:120px;}
%d 博主赞过: