Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.