Created
April 7, 2021 18:43
-
-
Save shoreline-chrism/6a95b9d310aa4bf6a219258f1b280ce4 to your computer and use it in GitHub Desktop.
Convert text on separate lines to <li> items. Useful for custom fields where you want the user to input things on separate lines, but want them as a bullet list on frontend. In ACF, set the field type to 'wysiwyg' and use get_field() to get the text without HTML formatting by passing false to last argument.
This file contains 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 | |
// Convert text on separate lines to li items | |
if ( !function_exists( 'sl9_text_to_li' ) ) { | |
function sl9_text_to_li( $text ) { | |
global $shortcode_tags; | |
$pattern = | |
'/' | |
. '((?!\R).+\R?)' // All lines of text | |
. '/m'; | |
return preg_replace( $pattern, '<li>$1</li>', $text ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment