WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

One of my posts has the following content:

This is a test post. Nothing more,
nothing less.
Three lines before the jump
And a couple of more lines
after the jump.

Note: these were written as you see them, in the WP editor, using the HTML tab - so we have no hidden <br> or anything else going on in the post content.

Also: No Manual Excerpt was defined for this post.

If I use the_content(), I get this:

<p>This is a test post. Nothing more,<br /> 
nothing less.<br /> 
Three lines before the jump</p> 
<p><a href="...#more-1336" class="more-link" title="Continue Reading">&raquo;</a></p> 

If, however, I use echo get_the_excerpt(); I get this:

This is a test post. Nothing more, nothing less. Three lines before the jump

No <p>s, nor <br />s (heck, not even the [...] I was half-expecting!)

What I'd really like to achieve in my theme is (within The Loop, of course):

  1. If a manual excerpt exists: display that (and I know I'll have to tweak the [...])
  2. Else, display the content, respecting any <!--more--> you may find.

So, I was starting with this

$excerpt = get_the_excerpt();
if($excerpt=='') { //right, isset or empty may be better
} else {
    echo $excerpt;

But I'm getting the feeling there's a better way? Or is there a quick fix for the formatting issue mentioned above?

share|improve this question
up vote 2 down vote accepted

the_content() and the_excerpt(), unlike their 'get_' brothers will process the content through some functions, one of them is wpautop() that will add p tags for you. To get the same formatting for both excerpt and content:

if ( has_excerpt() ) {
} else {
  the_content(__('Read more'));
share|improve this answer
Lovely! Thanks for the tip (I knew of wpautop() but didn't realize it did more than enclosing in <p>s – FOR Mar 4 '11 at 15:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.