WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
share|improve this question
up vote 0 down vote accepted

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;
share|improve this answer
Yep, that takes care of it. Thanks for the help! – mediaryte Jul 29 '13 at 2:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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