简体   繁体   English

WordPress主题-删除未使用的CSS

[英]Wordpress theme - remove unused css

I have a wordpress theme and I want to remove unused css. 我有一个wordpress主题,我想删除未使用的CSS。 So I try to use Gulp+uncss 所以我尝试使用Gulp + uncss

Theme Folder structure 主题文件夹结构

CSS/main.css
-gulpfile.js

Wordpress site url localhot/wpsite WordPress网站网址localhot / wpsite

And I have gulpfile.js 我有gulpfile.js

//Include Gulp
var gulp = require('gulp');

//Include plugins
    var uncss = require('gulp-uncss');
    var rename = require('gulp-rename');

    //Uncss task
    gulp.task('uncss', function() {

        gulp.src('css/main.css')  
            .pipe(uncss({        
                html: [  'http://localhot/wpsite/','http://localhot/wpsite/about' ]  
            }))      

        .pipe(rename({suffix: '.clean'}))
        .pipe(gulp.dest('css'));

    });

But I can`t get new clean css file 但是我无法获得新的干净的CSS文件

After you see the above(your code) gulpfile.js 看到上面的(您的代码)gulpfile.js之后

If you have just a few pages, like 20 or less, you can just go ahead and copy and paste the URL's if not then you will need a plugin for this. 如果只有几页,例如20页或更少,则可以继续复制并粘贴URL(如果没有),则需要一个插件。 There's a plugin that is designed for Grunt but also works fine with Gulp. 有一个专门为Grunt设计的插件,但也可以与Gulp配合使用。 You can find it here with easy-to-follow instructions on how to use it. 您可以在此处找到有关如何使用它的易于遵循的说明。

After you activate it, go to: 激活后,请转到:

http://yourdomain.com?show_sitemap http://yourdomain.com?show_sitemap

You'll see some code, just Select all and copy then paste it in the gulpfile.js inside the uncss function after “html:” 您将看到一些代码,只需全选并复制,然后将其粘贴到“ html:”之后的uncss函数内的gulpfile.js中即可。

After you copy the array, save the file. 复制阵列后,保存文件。 Then, in the command-line, type: 然后,在命令行中键入:

gulp uncss

So now, if you look at your CSS folder or wherever you chose for your destination path, you will see a new lean CSS with the suffix '.clean' that should look something like this: 因此,现在,如果查看您的CSS文件夹或为目标路径选择的任何位置,您将看到带有后缀“ .clean”的新精益CSS,其外观应类似于以下内容:

在此处输入图片说明

Check once the below link. 检查以下链接。 It will clearly describes, How to Remove Unused CSS in WordPress Using Gulp from the gulp installation 它将清楚地描述如何从gulp安装中使用Gulp删除WordPress中未使用的CSS

Remove Unused CSS 删除未使用的CSS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM