creativedotdesign / tofino

WordPress boilerplate theme on a modern stack. NPM and Composer.
Other
29 stars 6 forks source link

Update fix_text_orphan function #330

Closed danimalweb closed 2 years ago

danimalweb commented 3 years ago

Include the min number of words.

 * Fix text orphan
 *
 * Make last space in a sentence a non breaking space to prevent typographic widows.
 *
 * @since 3.2.0
 * @param type $str
 * @param type $min_word_count
 * @return string
 */
function fix_text_orphan($str = '', $min_word_count = 3) {
  $str   = trim($str); // Strip spaces.
  $space = strrpos($str, ' '); // Find the last space.
  $word_count = str_word_count($str);

  // If there's a space then replace the last on with a non breaking space.
  if ((false !== $space) && $word_count > $min_word_count) {
    $str = substr($str, 0, $space) . ' ' . substr($str, $space + 1);
  }

  // Return the string.
  return $str;
}
Malcolm-Remple commented 3 years ago

Pending merge