In the administration area of WordPress, the text editor that you actually type into when writing posts is actually a javascript platform called TinyMCE. By most accounts it’s a pretty nice WYSIWYG editor that really gets the job done, but it’s not without some complaints.
A common complaint amongst WordPress bloggers is the inability to space out blocks of text. You can put as many returns between your paragraphs as you want, you aren’t going to get them, and TinyMCE is to blame. Every time you press return in a blog post, TinyMCE puts the text above it into paragraph (<p>) tags. Pressing returns multiple times should get you bunch of empty paragraph tags, which would result in several line breaks, but empty paragraph tags are intentionally removed by TinyMCE. Even if you manually add <br /> tags, they will be removed before the post is published.
TinyMCE is actually just trying to be helpful and save you from yourself. Spacing out content is a design decision, not a content decision. And what is the guiding theory behind CSS? CSS separates content from design. If you want more spacing between your paragraphs, do it in your CSS.
This is all it takes:
p {
margin-bottom: 1.5em;
}
Since each block of text in your post will be automatically wrapped in a paragraph tag, adding some margin-bottom will handle the spacing nicely. You could also use padding here, since paragraphs are block-level elements.
By the way, the same space-stripping applies to comments. Comments are treated in the same way as posts though, with paragraph tags around blocks of text, so the margin-bottom you apply for formatting your posts will work in your comments as well. Consider this a favor to your commentors. If they want to break up their comments into paragraphs, they should be able to do so and have it displayed properly.
If you have a really good reason why you need to be able to add line breaks in your posts, you do have some options. This thread over at the WordPress forums details some edits to code that might be able to get the job done for you. All of the solutions boil down to the fact that hard returns in your posts are saved to the database as “/n” and they can be converted into break tags if need be.
<p> </p>
Putting that inside your posts will force an extra line break if you absolutely need it. But don’t tell anybody I told you.
For a few more WordPress-specific CSS Tricks, check out my recent article on my favorites.
Author comments are in a darker gray color for you to easily identify the posts author in the comments
Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums
Thanks for writing this, I have been finding the line breaks thing really annoying.
I find that if I write it all in the visual editor and don’t switch over to code at all the line breaks will stay where I put them. But if I switch to code and then back to visual, game over. ;(
I’ll try that code you put here.
Cheers!
Snoskred
very useful, thank you.
Cool, glad you folks found it useful.
Wow, a very nice idea and a very impressive blog!
Oh thank you! This was a perfect fix for my wordpress line brake problem – I am glad I thought I was going to have to change themes.
A+++