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

powered by WassUp

Recent Posts: Fully Net Worth . com

Alejandro Rosario Net Worth: How Rich is the Tik Tok star?

Alejandro Rosario Net Worth: How Rich is the Tik Tok star?

Alejandro Rosario is an up and coming Internet superstar who is famous for his activities on an app called Tik Tok. Within a couple of months, Rosario has been able to gain a huge following on his Tik Tok account. As of 2019, Alejandro Rosario net worth is estimated to be $100,000. Alejandro was born […]

Cyril Hanouna Net Worth: How Rich is the French TV Star?

Cyril Hanouna Net Worth: How Rich is the French TV Star?

Cyril Valéry Hanouna is a French radio and television presenter, writer, and producer. Hanouna is a polarizing figure who is best known for being the host of the popular French TV show Touche Pas à Mon Poste! As of 2019, Cyril Hanouna net worth is estimated to be $5 million. Hanouna was born on 23 […]

Donna Marie Lombardi Net Worth- How Rich is Black Ink Crew Star?

Donna Marie Lombardi Net Worth- How Rich is Black Ink Crew Star?

Taylor Monet Pinkney, who is better known as, Donna Marie Lombardi, is a tattoo artist and an influencer. She is best known for playing an important role in the reality television series called Black Ink Crew which airs in VH1. As of 2019, Donna Marie Lombardi net worth is estimated to be $350,000. Donna was […]