Connect with us

Tips & Tricks

Display the_excerpt only if there is text

Have you ever wanted to display the excerpt only if you write one? A simple couple lines of code can display the_excerpt any where you like.

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.

2 Comments

2 Comments

You must be logged in to post a comment Login

Random Search Terms

Title

Top Articles

Top Searches

powered by WassUp

Recent Posts: Fully Net Worth . com

Summer Walker Net Worth: 5 Interesting Facts You Should Know

Summer Walker Net Worth: 5 Interesting Facts You Should Know

Summer Marjani Walker is an American singer-songwriter who is currently signed with LoveRenaissance¬†and¬†Interscope Records. Here are some interesting facts about Summer Walker: 1. She considers Amy Winehouse early childhood inspiration Walker was born on April 11, 1996, in Atlanta, Georgia. She has kept much of her childhood disclosed but in an interview, she did mention […]

Fiona Hill Net Worth: How Rich is Fiona Hill Actually?

Fiona Hill Net Worth: How Rich is Fiona Hill Actually?

Fiona Hill is a British born American foreign affairs specialist. Hill previously worked as a former official at the National Security Council specializing in Soviet, Russian, and European Affairs. As of 2019, Fiona Hill net worth is estimated to be $1.5 million. Hill was born in October of 1965, in Bishop Auckland, County Durham in […]

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg is the mayor of South Bend, Indiana. He is also an American war veteran and a former consultant. In the recent days, Buttigieg has been growing his name with him announcing candidacy for the Presidential election in 2020. Then President Obama called him as one of four Democrats who represented the future of […]