Skip to content

Instantly share code, notes, and snippets.

@justinallen
Created February 13, 2019 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinallen/636a918ea289647307ff006b6862bd12 to your computer and use it in GitHub Desktop.
Save justinallen/636a918ea289647307ff006b6862bd12 to your computer and use it in GitHub Desktop.
// great little typographic widow control script from chris coyier
// https://css-tricks.com/preventing-widows-in-post-titles
$("h2 a").each(function() {
var wordArray = $(this).text().split(" ");
if (wordArray.length > 1) {
wordArray[wordArray.length-2] += " " + wordArray[wordArray.length-1];
wordArray.pop();
$(this).html(wordArray.join(" "));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment