Created
December 1, 2019 20:28
-
-
Save BinaryMoon/05f9f98d4d34fd28c1d9c60684016d0b to your computer and use it in GitHub Desktop.
Widont
This file contains 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
<?php | |
/** | |
* Add 'fix' for typographic widows | |
* This is the same code used on wordpress.com | |
* | |
* @param type $str | |
* @return string | |
*/ | |
function theme_widont( $str = '' ) { | |
$str = rtrim( $str ); | |
$space = strrpos( $str, ' ' ); | |
$count = substr_count( $str, ' ' ); | |
if ( $count <= 1 ) { | |
return $str; | |
} | |
if ( false !== $space ) { | |
$str = substr( $str, 0, $space ) . ' ' . substr( $str, $space + 1 ); | |
} | |
return $str; | |
} | |
add_filter( 'the_title', 'theme_widont' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment