Last active
December 11, 2016 16:36
-
-
Save kyleturman/6971f1fe2ac6eb4935ff00009c3315e4 to your computer and use it in GitHub Desktop.
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 | |
// Prevent Widows Kirby CMS plugin | |
// Makes line breaking text go from: | |
// Lorem ipsum dolor sit amet, consectetur adipiscing | |
// elit. | |
// To: | |
// Lorem ipsum dolor sit amet, consectetur | |
// adipiscing elit. | |
// Put in your site/plugins folder | |
field::$methods['kirbytext'] = field::$methods['kt'] = function($field) { | |
// Adds char before second to last word | |
// Regex from http://www.webmastertools.bz/simple-php-regex-script-to-prevent-orphans-in-paragraph-text/ | |
$textNoWidows = preg_replace('/\s([\w]+[.,!\:;\\"-?]{0,1})$/', ' \\1', $field->value); | |
// Runs kirbytext like normal | |
$field->value = kirbytext($textNoWidows); | |
return $field; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment