The Must Have for WordPress
The Must Have for WordPress
×
  • Home
December 5, 2019
CSS PHP

Minify or compress CSS in PHP

by Martin Jost
No comments
1 min Reading Time
509 Views
5 Score
3 Likes
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp

For developers of plugins or themes, it is important to provide the included CSS (stylesheets) files to the user in a compressed or minified version. This mainly benefits the page speed of the website and is very helpful for the search engine optimization as well as for the user experience itself.

How can I compress CSS files?

The following PHP function provides an easy way to compress CSS files without having to manually do it each time you edit a stylesheet file. A compressed file version of the original CSS file could be easily stored in a temporary folder and retrieved if the file exists. This saves a considerable amount of CSS code and reduces the file size.

How do we use the CSS Minify function?

The function minify_css( $file_content ); ensures that all unnecessary tabs, spaces, breaks, and comments in the CSS file are removed. As result, we get a compressed and minified version of the file content.

Last updated: December 5, 2019

Minify or compress CSS in PHP Score: 5 / 5 (1vote)
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp
The Author
Published by
Martin Jost

View all posts by Martin Jost

Related Posts
R
WordPress Remove the URL field in the WordPress comments form

As we know, comments are often misused by website visitors to get external links. Outgoing links ...

Read More
G
PHP Get the installation URL of WordPress

In some cases, it can be very helpful to use the WordPress installation URL for a PHP validation ...

Read More
U
PHP Use PHP to remove certain characters or words from a string

The default PHP function str_replace(); is a useful tool if we want to remove certain characters ...

Read More
Read more
M
Previous Post
Minify and compress Javascript files in PHP
G
Next Post
Get the installation URL of WordPress
Leave a Reply Cancel reply

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

  • Imprint
  • Privacy Policy
© 2016-2021 - wphave - The Must Have for WordPress
Login

Lost your password?

RequiredEssential cookies enable basic functions and are necessary for the proper functioning of the website.
  • Name: Cookie Status
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user's web browser allows cookies.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookie_status
  • Duration: 1 Minute
  • Name: Cookie Consent
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user agrees to allow opt-in cookies or not.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookieconsent_analytics, cookieconsent_marketing, cookieconsent_status
  • Duration: 1 Year
  • Name: Like Button
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already gave a like for a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): like_btn_{POST_ID}
  • Duration: 21 Days
  • Name: Post Rating
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already rate a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): rating_{POST_ID}
  • Duration: 7 Days
AnalyticsStatistics cookies collect information anonymously. This information helps us to understand how our visitors use our website.
  • Name: Google Analytics
  • Provider: Google LLC
  • Purpose: Google cookie for website analysis. Generates statistical data on how the visitor uses the website.
  • Privacy Policy: https://policies.google.com/privacy
  • Cookie Name(s): _ga, _gat, _gid
  • Duration: 2 Years