Site logo

Archived topic

Leave excerpt empty unless specific excerpt entered

7 replies · Started by Jeffrey on December 12, 2021

Viewing posts 1–8 of 8

Hey,

Can anyone help me figure out how to leave the default excerpt empty unless it is explicity specified?

Example:
If I leave excerpt empty, it shows the first X amount of words and then "...read more".
Instead, I want it to just remain empty unless I write an excerpt to be displayed.

Thanks so much!!

Hi there,

You can try adding this CSS:

.inside-article .entry-content {
    display: none;
}

This ensures that only posts with actual manual CSS will show content on post items.

Hey,

Can you check out my website?
The first article is what I want it to show - it's showing the excerpt right under the title
The second article, I did not enter an excerpt, and it is showing the default excerpt, which is a portion of the actual post. Is there a way to get rid of the default action?

These pages you've linked are single post pages. The CSS I've provided won't work on it.

The theme, by default, only displays excerpts on archive pages and the blog index page.

This one - https://share.getcloudapp.com/12uPXjyq - I assume, is added by a shortcode.

Is it a custom one? If yes, can you share the snippet for the shortcode? So we can check it out and help w/ how to change it to your specific requirement.

Yeah you're correct Elvin, the shortcode is simple:

/*Excerpt shortcode for header*/
add_shortcode( 'output_post_excerpt', 'get_the_excerpt' );

And I just put it into the header element for a single post

Replace it with this:

add_shortcode( 'output_post_excerpt', function() {
		global $post;
		$the_post_excerpt = $post->post_excerpt;
    ob_start();
    // Start your PHP below
  
    if($the_post_excerpt){
				echo $post->post_excerpt;
	 	} 
    // End your PHP above
    return ob_get_clean();
} );

This worked!! Thanks so much - genius

No problem. :D

This archived topic is closed to new replies.