wordpress日常优化

来源:互联网 发布:c语言转汇编 编辑:程序博客网 时间:2024/06/11 11:14

1.禁用geogle字体
在主题中的 functions.php 文件中添加以下代码:

//关闭geogle字体
class Disable_Google_Fonts {
public function __construct() {
add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 );
}
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
}

$disable_google_fonts = new Disable_Google_Fonts;

2.缩略图改为固定裁剪的缩略图

缩略图是通过deel_thumbnail函数进行提取的,一般在主题的functions.php中,没有对图片进行裁切压缩,下面是我优化后的函数代码
/*缩略图*/
if ( ! function_exists( 'deel_thumbnail' ) ) :
function deel_thumbnail() {
global $post;
if ( has_post_thumbnail() ) {
$domsxe = simplexml_load_string(get_the_post_thumbnail());
$thumbnailsrc = $domsxe->attributes()->src;
echo '<img width="220" height="150" src="'.$thumbnailsrc.'" alt="'.trim(strip_tags( $post->post_title )).'" />';
} else {
$content = $post->post_content;
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if($n > 0){
echo '<img width="220" height="150" src="'.get_bloginfo("template_url").'/timthumb.php?src='.$strResult[1][0].'&w=220&h=150&zc=1" alt="'.trim(strip_tags( $post->post_title )).'" />';
}else {
echo '<img width="220" height="150" src="'.get_bloginfo('template_url').'/img/thumbnail.png" alt="'.trim(strip_tags( $post->post_title )).'" />';
}
}
}
endif;

改成固定大小220*150,具体裁剪是情况而定