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

‘Portal’ And ‘Left 4 Dead 2’ Arrive On Linux

Steam is powerful, hot, and painful. It can move trains, boats, and has driven minds…

2 mins ago

Swekey: A safe web enabler usb?

I received a Swekey in the mail this week. What's a Swekey you ask? Like…

12 hours ago

Add additional meta boxes to Hybrid Theme

At the time of writing this post I have Theme Hybrid as my parent theme,…

2 days ago

What do Software as a Service (SaaS) Companies Do?

What do Software as a Service (SaaS) Companies Do?

2 days ago

Sick of images being to large for the content area?

Have you ever uploaded an image that might have been a tad bigger than the…

3 days ago