Skip Navigation

[Resolved] Unexpected HTML output when using Multiple Lines Field

This thread is resolved. Here is a description of the problem and solution.

Problem:
When inserting a Multiple Lines Field in a Content Template, Post or View loop, it seems that it automatically wraps it's contents in a paragraph, provoking a line break after and before it's content.
How can we avoid this?

Solution:
Multiple Lines come by default with HTML ready content wrapped in a minimal tag which is the Paragraph.
You can avoid that paragraph by telling the ShortCode to return RAW values as saved in the database.
This will still execute the HTML inside the Multiple Lines Field if you added any, but it won't add the wrapping Paragraph.
You can see an example here https://toolset.com/forums/topic/the-line-is-broken-in-views/#post-1276355

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by deepS 4 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#1274891
Screenshot_2.jpg

I have created a view of a repeatable group of fields and wanted to show on a page. The views are working fine. But when I put labels before the values generating from custom fields, the line is breaking after the label. I have used the following code

<h3>Name of the Post: [types field="post-name"][/types]</h3>
<ul>
<li>No. of Vacancies: [types field="vacancies"][/types]</li>
<li>Uppre Age Limit: [types field="upper-age-limit"][/types]</li>
<li>Educational Qualification: [types field="educational-qualification"][/types]</li>
<li>Work Experience: [types field="work-experience"][/types]</li>
<li>Pay Scale: [types field="pay-scale"][/types]</li>
</ul>

Things are generating in a different way. You can understand the problem from the attached screenshot.

#1274903

In the Content Template or Template Loop Item where you added that code, uncheck the "Auto-insert paragraphs" option and select "Manual paragraphs" instead - that is one part that can solve the issue of unexpected P tags or breaking tags

Another part is outputting the Field in "Raw" mode (output="raw"). That ensures the Fields are only outputting values and no HTML.
It seems you need to do this only for [types field="educational-qualification"][/types], [types field="work-experience"][/types]

Maybe those are WYSIWYG or other HTML carrying fields? Then it's expected for them to output in certain wrapping HTML.
You can ultimately also try to wrap content into "[wpv-noautop]CONTENT HERE[/wpv-noautop]" ShortCodes, this ensures that anything within is rendered without HTML applied.

Please let me know which of the options solved the issue, or if you still see the problem after all changes applied.

#1275081
Screenshot_1.jpg

See for the 'Educational Qualification' and 'Work Experience' fields I am using 'multiple lines; custom fields whereas in other cases either I am using number or single line custom fields.

I have tried all the tricks including generating views out of the customs in an unformatted way but its adding paragraph tag for those two fields. But when I keep the custom field of a 'single line' nature, the problem doesn't persist (keeping the custom field of 'multiple lines' nature is my compulsion).

See the screenshot.

#1276355

Multiple Lines Fields accepts HTML when edited in a Post
Do your Multiple Lines Fields hold any HTML?

Even if you just break line in the Multiple Lines Field, this will (natively) be respected on the Front end, so it will look like when inserted in the backend.
Each Multiple Line Custom Field will output a P tag, in it several BR tags to separate the lines in the Field.
However, as I mentioned earlier, if you select raw output when inserting this ShortCode, then the P tag is not produced.

The ShortCode with raw output can be generated by the GUI when inserting it, and this is how it should look alike:

[types field='multi-line-field-slug' output='raw'][/types]

As soon this is done, no more P tag will be wrapping the content of that Multiple Line, neither will the line breaks in the field apply, of course, as now it's "raw", and only really saved values of the field will be shown/returned.

Hence if you still see the issue with the raw turned on, then the problem is in the content of your Multiple Lines field, since if you add valid HTML there, it won't be removed by the raw attribute.
Then, you need to change the HTML in the content of the Multiple Lines field.

#1276749

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.