• Is this even possible? I understand the WP cleaner parses everything and does what it wants, but is there any kind of SIMPLE workaround/hack/escape method to let these through?

Viewing 10 replies - 1 through 10 (of 10 total)
  • In where? Post content? A plugin?

    Thread Starter ixwa

    (@ixwa)

    Didn’t really think that mattered but right now I’m trying to include it in some Page output, but it’s printing it literally.

    It matters…

    If you are adding these line breaks to content in a Page or Post via the HTML or Visual Editors, WP will turn the newline into an HTML <br /> tag. If you don’t see these breaks on the published page, your theme may be removing them by using the_excerpt() or doing something funky instead of using the_content().

    Thread Starter ixwa

    (@ixwa)

    OK I’m not sure if I properly communicated what I’m looking for:

    I’m aware that WP normally replaces \n (and presumably \r\n etc) with <br /> But is there a method to escape this or to in some other way include a physical line break in the outputted HTML?

    (This behavior, I’ve noticed, occurs across the board in Posts, Pages and my PHP scripts, without exception.)

    Why do you need to escape it? Or require a physical newline in the page source?

    If you are within the wysiwig editor (the bit where you put page content), there is an “visual” / “html” tab. If you switch to HTML, place your “
    ” tag in where it needs to be and press update.

    If it is getting rid of the
    tag still, try giving it the “preformatted” format instead of paragraph, it should stop it overwriting what you want it to do.

    Esmi has a point though, I can’t think of any websites where i’ve needed such a thing

    Thread Starter ixwa

    (@ixwa)

    For development. While coding pages it’s often necessary to break up the output of, for example, the loop into segments that can be more easily read for design/code/layout tasks (especially when the loop output is deep).

    Not having newlines is ultimately better for publishing since it saves a little space being minimized, but otherwise it’s a jumble trying to read it in the early stages.

    FYI: This is all in an external editor, not the WP dashboard edit window.

    Thanks anyway…will have to devise a workaround.

    In PHP you can just use ."\n" when, for example, outputting a list item by item. But anything that passes through the content folder (eg the_content(), the_excerpt() etc) will have those new lines stripped out, so you’d need to look at get_the_content() etc instead.

    Try “\n” instead of ‘\n’, no idea why, but this works

    I found the answer to this issue here, it is very simple and does the trick!

    https://www.webmasters-central.com/article-blog/blogging-and-autoblogging/wordpress-line-break-and-paragraph-problem-and-how-to-fix-it/

    Full credit goes to the author of the post ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Insert a newline \n character in WP?’ is closed to new replies.