Categories: Tips & Tricks

Display the_excerpt only if there is text

In my new theme, I am using this coded trick to display the excerpt on a single post only if I’ve got text inside. Usually if you use the_excerpt and you don’t have one, it will fake one for you.

This is not something that I wanted to do on the single post page. So I used the following code to check if the excerpt existed.

if ( !empty( $post->post_excerpt ) ) :

Once this action is taken into account, you can factor in what code you want to out put if the post_excerpt isn’t empty.

if ( !empty( $post->post_excerpt ) ) :
 the_excerpt();
else :
 false;
endif;

The above code checks if there is an excerpt and print’s it to the screen. If there isn’t an except, it doesn’t do anything.

Web Master

Hi, I am Miguel, I bought this site in 2009. So I now run or manage the site. Please visit my new website or follow me on twitter @W3i.

Recent Posts

Weblog Tools Collection: WP-commerce Podcast

Jeff Chandler has done a great interview with Dan Milward of Instinct. Check it out…

5 days ago

WPZoom: WordPress related Firefox Addons

Firefox is regarded as the best Web browser in terms of extensions. It has hundreds…

6 days ago

MissyWard.com

6 days ago

cforms II now GPL compliant

Well, it was a long run, ok, only 24 hours when Mr. Seidel's announced that…

7 days ago

Goodbye to cforms II

If you are using the cforms II, you may want to head over to Mr.…

1 week ago

Revolution Two: Church Theme

Benefits include the Church theme, unlimited theme support answered by our experts, customization techniques with…

1 week ago