Last active
April 6, 2017 08:06
-
-
Save BinaryMoon/7f8f6f1e9d111f3650cb504ee92e8f27 to your computer and use it in GitHub Desktop.
Remove Widows from text in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Make last space in a sentence a non breaking space to prevent typographic widows. | |
* | |
* @param type $str | |
* @return string | |
*/ | |
function theme_widont( $str = '' ) { | |
// Strip spaces. | |
$str = trim( $str ); | |
// Find the last space. | |
$space = strrpos( $str, ' ' ); | |
// If there's a space then replace the last on with a non breaking space. | |
if ( false !== $space ) { | |
$str = substr( $str, 0, $space ) . ' ' . substr( $str, $space + 1 ); | |
} | |
// Return the string. | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment