CorePress主题优化
优化内容:
- 加入了font-display: swap;属性,可确保在加载Web字体时用户可见文本.
- 压缩了CSS文件
- 利用Nginx可对js以及字体文件进行本地缓存
Webfonts字体优化
# 下载fonts文件到主题目录下
wget -P /wp-content/themes/CorePress/static https://github.com/lanyixuanli/Webfonts/blob/main/webfonts.tar.gz
# 解压
tar -zxvf /wp-content/themes/CorePress/static/webfonts.tar.gz
# 删除压缩包
rm -rf /wp-content/themes/CorePress/static/webfonts.tar.gz
Css文件优化
# 下载css文件到主题目录下
wget -P /wp-content/themes/CorePress/static/css/ https://raw.githubusercontent.com/lanyixuanli/Webfonts/main/all.min.css
Utils php文件优化
替换utils.php
中loadiconfont_by_cdn
函数内容vim /wp-content/themes/CorePress/geekframe/utils.php
function loadiconfont_by_cdn()
{
echo '<link rel="stylesheet" href="/wp-content/themes/CorePress/static/css/all.min.css?v=' . THEME_VERSIONNAME . '">';
}
优化Header php文件
如果不想用主题提供的字体也可以将header.php
文件中的以下内容注释掉vim /wp-content/themes/CorePress/header.php
if ($set['theme']['font'] != 'no') {
echo '<link rel="stylesheet" type="text/css" href="https:[email protected]/static/lib/font/' . $set['theme']['font'] . '/font.css">';
?>
<style>
html, textarea {
font-family: <?php echo $set['theme']['font']?>, PingFang\ SC, Hiragino\ Sans\ GB, Microsoft\ YaHei, STHeiti, WenQuanYi\ Micro\ Hei, Helvetica, Arial, sans-serif !important;
}
</style>
<?php
}
优化Nginx Conf文化
#缓存静态文件
location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|webp)$ {
root 网站根目录;
expires 30d;
}
#缓存静态文件
location ~ .*\.(eot|woff|woff2|ttf)$ {
root 网站根目录;
expires 30d;
}
# expires 30s; 30秒
# expires 30m; 30分钟
# expires 2h; 2个小时
# expires 30d; 30天
优化主页缩略图alt
给/wp-content/themes/CorePress/component/post-list-item.php
中的$imgtag
变量添加alt
属性,alt
内容为当前文章的标题
# 修改后的代码
if ($set['module']['imglazyload'] == 1) {
$pathname = 'data-original';
$imgtag = '<img src="' . file_get_img_url('loading.gif') . '" data-original="' . $postitem['thumbnail'] . '" alt="'.$postitem['title'] .'">';
} else {
$imgtag = '<img src="' . $postitem['thumbnail'] . '"alt="'.$postitem['title'] .'">';
}
优化友情链接无ul
/wp-content/themes/CorePress/index.php
<div class="frinds-links-list">
<ul>
<?php wp_list_bookmarks('title_li=&categorize=0&show_images=0&category=' . $set['index']['links_ids']); ?>
</ul>
</div>
wp-content/themes/CorePress/static/css/main.css
/*文件中的.frinds-links li Css样式替换为下面 */
.frinds-links li{float: left;font-size:15px;list-style:none;margin-right:20px;margin-bottom:6px;vertical-align:middle}
共有 0 条评论