Dave McCourt thinks some thoughts...

Strip spaces in WordPress

Posted in: Code snippets, WordPress

A particular bug-bear of mine is useless extra spaces in text. Unfortunately these are everywhere in client supplied text and text copied from websites. So here is a snippet to strip them out of WordPress. Credit.

function banana__remove_spaces($the_content) {
return preg_replace('/[\p{Z}\s]{2,}/u', ' ', $the_content);

add_filter('the_content', 'banana__remove_spaces');