Advertisement
Guest User

Compress CSS

a guest
Jan 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. if ( ! function_exists( 'polygon_compress_internal_stylesheet' ) ) {
  2.     /**
  3.      * Compress dynamic stylesheet.
  4.      *
  5.      * Compress the internal stylesheet by stripping all comments, spaces and empty lines.
  6.      * The function also places everything on the same line in order to make the source code
  7.      * easy to scan.
  8.      *
  9.      * @since  1.0.0
  10.      * @param  string $buffer Stylesheet generated by the options from the customizer.
  11.      * @return string         The compressed stylesheet stored in $buffer.
  12.      */
  13.     function polygon_compress_internal_stylesheet( $buffer ) {
  14.         // Remove comments.
  15.         $buffer = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer );
  16.         // Remove space before bracket.
  17.         $buffer = str_replace( ' {', '{', $buffer );
  18.         // Remove space after colons.
  19.         $buffer = str_replace( ': ', ':', $buffer );
  20.         // Remove tabs, spaces, newlines, etc.
  21.         $buffer = str_replace( array( "\r\n", "\r", "\n", "\t", '  ', '   ', '    ' ), '', $buffer );
  22.         return $buffer;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement