[Resolved] Leave excerpt empty unless specific excerpt entered

Home Forums Support [Resolved] Leave excerpt empty unless specific excerpt entered

Home Forums Support Leave excerpt empty unless specific excerpt entered

  • This topic has 7 replies, 2 voices, and was last updated 1 month ago by Elvin.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2046887
    Jeffrey

    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!!

    #2046902
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

    #2046948
    Jeffrey

    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?

    #2046998
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

    #2047014
    Jeffrey

    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

    #2047172
    Elvin
    Staff
    Customer Support

    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();
    } );

    A wise man once said:
    "Have you cleared your cache?"

    #2047728
    Jeffrey

    This worked!! Thanks so much – genius

    #2048099
    Elvin
    Staff
    Customer Support

    No problem. 😀

    A wise man once said:
    "Have you cleared your cache?"

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.