I use Advanced Custom Fields on nearly every client site I develop. One thing that’s kind of not cool about user generated content is the lack of control over non-breaking spaces between the last two words to prevent widows. But fear not! With this regex snippet from David Walsh, you can create a helper function in your custom theme and wrap all your ACF output (or just static text) in the helper that will insert a non-breaking space between the last two words.


// in functions.php
function word_wrap ($text) {
    echo $text = preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1 $2', $text);
}

// using it in your theme
word_wrap(get_field('field_name'));

Note: with ACF, make sure you use get_field and not the_field.