Adding spaces after punctuation
-
On a project in progress, I have to add aspaces after punctuation.(and before sometime)
It is a blog with more than 37000 posts. And the blogger has long drafted forgetting to add for example a space after:
–> ‘.’
–> ‘;’
–> ‘,’
–> ‘?’
and a space before and after:
–> ‘()’
–> ‘:’This is the code, thank you pepe (wp-typography) Based on the regex :
add_filter( 'the_content', 'spacify' ); function spacify( $text ) { $text = preg_replace( '@(\w+)(\.|;|,|!|\?|\))(\S)@u', '$1$2 $3', $text ); $text = preg_replace( '@(\w+)(:)(\S)@u', '$1 $2 $3', $text ); return $text; }
[Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]
this code is ok but breaking the links in the text and missing space before ‘(‘
Anyone with an idea?
There are no existing plugins for this and the best way is this.
The best solution is to call the community for it, I’m sure that I am not the only one to have this type of problem…
- The topic ‘Adding spaces after punctuation’ is closed to new replies.