Have you ever found yourself in a situation where your custom theme is not displaying the text properly? If yes then there is a chance you might be able to fix your problem today by going through this article. I recently came across a similar problem for my custom theme and after doing some debugging and Googling I found the solution and realized few things that I wasn’t aware of before.
After wordpress verison 3.2 wordpress removed <p> and <br> tags from the editor. Since then its been using spaces to identify the line breaks. So every time when you press Enter it adds a double space and pressing Shift+Enter adds a single space which is stored in the database.
Now if you are try to get the content directly from the database you will get the spaces instead of line breaks. In order to solve this problem wordpress uses a filter named wpautop
//Replaces double line-breaks with paragraph elements. wpautop ( string $pee, bool $br = true );
This filter changes the double line-breaks in the text into HTML paragraphs.
// Start Text $some_long_text = (p)Some long text(/p) (p)that has many lines(/p) (p)and paragraphs in it.(/p) // end text echo wpautop( $some_long_text );
will give you
Some long text that has many lines and paragraphs in it.