+92 308 5039935
Get a Free Quote
+92 308 5039935

How to minify CSS in WordPress Theme or Plugin

How to minify CSS in WordPress Theme or Plugin

Minification is used to remove unnecessary elements, e.g: extra spaces. There are a lot of php scripts to minify or compress the css but we are going to use a simple function  here. It is usually used for inline css in WordPress.

 

We will name the function minify_css() with $css parameter/argument which will be used to pass the css for minification. There is not much to explain in the following function as you can see what the preg_replace() and str_replace() functions are replacing step by step.

 

Hello, I am a web designer and developer working since 2013. I build WordPress themes, write and extend WordPress plugins, edit WordPress themes and plugins in accordance to customer needs and play games when free ;-)
Related Post
How to add inline CSS in WPBakery Page Builder Element

WPBakery Page Builder (Formerly Visual Composer) is one of the best drag and drop front-end/back-end builder. You can easily apply inline css using style attribute but what if you need to apply css to a pseudo elements?

Read more
How to Auto Load Files in WordPress?

You may need to auto load files in WordPress themes or plugins. But I wouldn’t recommend it if you are creating theme to sell on themeforest. They didn’t accepted themes with this auto load function few years ago when we used

Read more
How to create WordPress plugin

Plugins are used to extend WordPress functionality or add a new feature. There are more than 54K+ plugins available free at WordPress Plugins directory and tons are available at other markets places.

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *