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
2.27 K Views
5 Score
4 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
L
WooCommerce Load WooCommerce Templates from Plugin files

By adding a ../wp-content/themes/my-theme/woocommerce/ folder to a WordPress theme, WooCommerce ...

Read More
O
WordPress Open Graph in WordPress einbetten, ohne Plugin

Das Open Graph-Protokoll ermöglicht es, dass jede Webseite als “rich object” im &#82 ...

Read More
A
WordPress Add custom classes to the WordPress BODY tag

Anyone who develops their own theme with a customizable layout or settings a theme needs to add ...

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-2023 - 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