Created
February 21, 2015 21:31
-
-
Save joemcgill/89629cd4ac3cd975db89 to your computer and use it in GitHub Desktop.
A WordPress filter to avoid widows in your titles
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
<?php | |
/** | |
* A WordPress filter to avoid widows in your titles | |
*/ | |
function avoid_title_widows( $title ) { | |
// Find the last space. | |
$last_space = strrpos($title, ' '); | |
// Replace it with a non-breaking space. | |
if ( $last_space ) { | |
$title = substr($title, 0, $last_space) . ' ' . substr($title, $last_space + 1); | |
} | |
return $title; | |
} | |
add_filter('the_title', 'avoid_title_widows'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment