Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
T5 Strip double spaces in posts
<?php
/**
* Plugin Name: T5 Strip double spaces in posts
* Description: Replaces [space + no-break-space] with a regular space.
* Plugin URI: http://wordpress.stackexchange.com/questions/75197/remove-double-space-after-a-period
* Version: 2012.12.06
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_filter( 'wp_insert_post_data', 't5_strip_double_spaces', 20 );
/**
* Filter post content.
*
* @wp-hook wp_insert_post_data
* @param array $data
* @return array
*/
function t5_strip_double_spaces( $data )
{
// see http://www.fileformat.info/info/unicode/char/a0/index.htm
$pattern = "~ \x{C2}\x{A0}~m";
$data['post_content'] = preg_replace( $pattern, ' ', $data['post_content'] );
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment