1

I'm using a plugin called Meta Sliders and I'd like my captions to keep the new line I input when I write them.

I found the function that I think prints the text: $caption = esc_textarea( $this->slide->post_excerpt );

I've read that the esc_textarea() removes the line breaks... How can I keep them?

Thanks!

1
  • The thing is, when I view the code, there are line breaks, but just in plan text, no <p> no <br> no nothing...
    – user3219369
    Sep 25, 2016 at 15:41

2 Answers 2

0

One dirty way I can think of, is first str_replace the line break to something else (for example [br]) then do the esc_textarea and then str_replace [br] back to line breaks. Not pretty and maybe not the best way, but it works.

1
  • I didn't fully understand but, I can input html tags like <br> and they work, but I need not to use them, as it's for a client's website.
    – user3219369
    Sep 25, 2016 at 15:35
0

try this:

    <?php wp_kses(nl2br($this->slide->post_excerpt), array('br'=>array())); ?>
3
  • Where? In the same php file that generates the captions?
    – user3219369
    Sep 25, 2016 at 18:46
  • instead esc_textarea( $this->slide->post_excerpt )
    – Raf
    Sep 25, 2016 at 18:47
  • Weird. Now, if I add a line break on the edit area and save it, nothing happens... but if I reload the page where the edit area is, it adds the <br /> tags there, and then of course there are line breaks on the slider's captions, but that's a strange behaviour and non acceptable for a client. Thanks for the idea though! I guess without looking a all the code it's difficult to guess where to add this function...
    – user3219369
    Sep 25, 2016 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.