Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created December 6, 2012 21:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefuxia/4228493 to your computer and use it in GitHub Desktop.
Save thefuxia/4228493 to your computer and use it in GitHub Desktop.
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