PurgeCSSPurgeCSS
API Reference
GitHub
API Reference
GitHub
  • PurgeCSS

    • About PurgeCSS
    • Getting Started
    • Configuration
    • Command Line Interface
    • Programmatic API
    • Safelisting
    • Extractors
  • Plugins

    • PostCSS
    • Webpack
    • Gulp
    • Grunt
    • Gatsby
  • Guides

    • Vue
    • React
    • Next.js
    • Nuxt.js
    • Razzle
    • WordPress
      • Installation
      • Usage
    • Hugo
  • Comparison
  • Common Questions

    • How to use with CSS modules
    • How to use with Ant Design

WordPress

If you want to use PurgeCSS with WordPress, you might need to safelist classes generated by WordPress to avoid them being removed by PurgeCSS. purgecss-with-wordpress contains the classes needed to be safelisted.

Installation

You need to install purgecss first.

Install purgecss-with-wordpress:

npm i --save-dev purgecss-with-wordpress

Usage

import Purgecss from 'purgecss'
import purgecssWordpress from 'purgecss-with-wordpress'

const purgeCss = new Purgecss({
  content: ['**/*.html'],
  css: ['**/*.css'],
  safelist: purgecssWordpress.safelist
})
const result = purgecss.purge()

If you have additional classes you want to include, you can include them using the spread operator:

{
  safelist: [
    ...purgecssWordpress.safelist,
    'red',
    'blue',
    /^red/,
    /blue$/,
  ]
}
Edit this page
Last Updated:
Contributors: Ffloriel, Christian Oliff, Floriel
Prev
Razzle
Next
Hugo