0

I am looking for a solution to add markup to a custom field with multiple lines. Much like wpautop, but with customization. I'm not quite sure to approach this with a custom function or something built into WordPress.

Custom Field text would be:

Line 1
Line 2
Line 3

Code output would add markup:

<span>Line 1</span>
<span>Line 2</span>
<span>Line 3</span>
0

I believe this is what you are after:

// define $post_id, $key, $single
$multipleLineValue = get_post_meta($post_id, $key, $single);

// Convert into an array where desired code can be added to the output
$multipleLineValue = explode("\n",$multipleLineValue);
$output = "";
foreach ($multipleLineValue as $lineValue) {
   $output .= "<span>".$lineValue."</span><br>";
}
echo $output;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.