CorePress主题优化概述
优化内容:
- 加入了font-display: swap;属性,可确保在加载Web字体时用户可见文本.
- 压缩了CSS文件
- 利用Nginx可对js以及字体文件进行本地缓存
Webfonts字体优化
1 2 3 4 5 6
| wget -P /wp-content/themes/CorePress/static https://github.com/JiangJiYue/yunwei/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文件优化
1 2
| wget -P /wp-content/themes/CorePress/static/css/ https://raw.githubusercontent.com/JiangJiYue/yunwei/main/all.min.css
|
Utils php文件优化
替换utils.php
中loadiconfont_by_cdn
函数内容vim /wp-content/themes/CorePress/geekframe/utils.php
1 2 3 4
| function loadiconfont_by_cdn() { echo '<link rel="stylesheet" href="/wp-content/themes/CorePress/static/css/all.min.css?v=' . THEME_VERSIONNAME . '">'; }
|
如果不想用主题提供的字体也可以将header.php
文件中的以下内容注释掉vim /wp-content/themes/CorePress/header.php
1 2 3 4 5 6 7 8 9 10
| if ($set['theme']['font'] != 'no') { echo '<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/ghboke/corepresscdn@master/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文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|webp)$ { root 网站根目录; expires 30d; } location ~ .*\.(eot|woff|woff2|ttf)$ { root 网站根目录; expires 30d; }
|
优化主页缩略图alt
给/wp-content/themes/CorePress/component/post-list-item.php
中的$imgtag
变量添加alt
属性,alt
内容为当前文章的标题
1 2 3 4 5 6 7
| 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
1 2 3 4 5
| <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
1 2
| .frinds-links li{float: left;font-size:15px;list-style:none;margin-right:20px;margin-bottom:6px;vertical-align:middle}
|