So I have a quote in my page template and I would like to give the user the opportunity to add line breaks whenever they desire to do so.

I wanted the blockquote to have an extra <p> tag inside the <blockquote> tag so I could style it better.

The problem I'm having now is that the <br /> tags are being removed. While using the wpautop() function they should stay.

Here is what I did:

$matched = preg_match("~(?<=<blockquote>)([\s\S]+?)(?=</blockquote>)~",
wpautop($child->post_content), $found); // find the quote in the content with regEx

$found = current($found);
$replace   = "<blockquote><p>".$found."</p></blockquote>";// add the <p> tag
$newphrase = str_replace($found, $replace, $found);

$clearQuote = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", '', 
wpautop($child->post_content, true)); // use wpautop to keep the <p> tag

Can anyone see why the <br> tag is being removed or do I need to add something else?

I came to realize that I don't think it has something to do with the wpautop() function.

The variable I use it in is used to filter it out of the_content(). So $clearQuote uses the found quote and deletes it from the_content() where $quoteFound uses the found value and doesn't use wpautop(). So it must be something else.

I added the wpautop() function to the $matched variable so it would add a <p> tag to where the user break the line. This way there isn't really a line break but the output is the same.

  • Where is this quote being entered? One purpose of wpautop is to turn a new line entered into a textarea into HTML line breaks without the user having to enter them themselves. – Jacob Peattie Feb 14 '18 at 10:52
  • The quote is being placed within the regular post_content editor. – Interactive Feb 14 '18 at 10:53
  • Then you shouldn't need to do anything. Users can already enter line breaks into quotes with Shift+Enter. Blockquotes have paragraphs in them added by wpautop, so why are you adding a paragraph around the entire contents of the blockquote? What if there's two paragraphs already? – Jacob Peattie Feb 14 '18 at 11:04
  • Well the problem is that I need to have <p> tags within the <blockquote> tags. – Interactive Feb 14 '18 at 11:06
  • They get added by WordPress, you shouldn't need to do anything. – Jacob Peattie Feb 14 '18 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.