Skip to content

Instantly share code, notes, and snippets.

@EmileBons
Last active March 15, 2016 15:27
Show Gist options
  • Save EmileBons/a8981313b978d7f94b80 to your computer and use it in GitHub Desktop.
Save EmileBons/a8981313b978d7f94b80 to your computer and use it in GitHub Desktop.
Modified Wordpress index.php to sanitize crap like empty lines caused by shitty plugins.
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment