How to format line breaks in custom fields in WordPress
I was working on a WordPress project where I needed to create some custom fields and format them for the user. I wanted to be able to create those fields so that the user only had to put a few bits of text into the fields and be done with it without having the need to know any HTML formatting.
I had this working fine for two fields called price and dimensions. The issues was that the output is a line of text, so all of the items were being displayed on one line and then wrapping to the next line even though there were page breaks in the fields themselves.
For the price field.
$159.99 for two nights.
Add one more night for $49.99
The output looked like:
$159.99 for two nights. Add one more night for $49.99
I fixed this in the page template file by adding the following code around the get statement.
wpautop
So my statement looked like:
ID, 'Price', true)); ?>
Now the output looks like I want:
$159.99 for two nights.
Add one more night for $49.99
Thanks a lot. Exactly what I needed
Hi David,
I was searching for this and I found you.
Your post helped me a lot.
Thanks.