Adding excerpt on posts (if that is added manually)

Community Forums Forums Design Tips and Tricks Adding excerpt on posts (if that is added manually)

This topic is: not resolved

This topic contains 2 replies, has 2 voices, and was last updated by  Anand Kumar 1 year, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #49938

    Anand Kumar
    Participant
    Post count: 17

    I am trying to add post excerpt on posts. The following code works but shows a part of post content if post excerpt is not added manually.

    I want to retrieve post excerpt only if there is a manually added excerpt for the post.

    Thanks in advance!

    The code is:

    /** Add post excerpt on posts */
    add_action( 'genesis_post_content', 'excerpt_on_post', 2 ); 
    function excerpt_on_post() {
        if ( is_single() ) {
    	echo '<div class="excerpt-on-post">
    				<p><span class="help">Summary: </span>';
    				$my_excerpt = get_the_excerpt();
    				echo $my_excerpt;
    		echo '</p></div>';
    	}
    }

    My two small blogs: NetRival | BlogSynthesis
    unanswerd

    • This topic was modified 1 year, 5 months ago by  Anand Kumar.
    • This topic was modified 1 year, 5 months ago by  Anand Kumar.
    http://www.netrival.com
    #50378

    Doak Heggeness
    Participant
    Post count: 145

    the_excerptis an option for posts under the ‘screen options’ tab. If it is left empty the_content is displayed.


    Doak Heggeness, WordPress Development | Website

    #53511

    Anand Kumar
    Participant
    Post count: 17

    I figured out the missing code. It was has_excerpt().

    So the code should be:

    /** Add post excerpt on posts */
    add_action( 'genesis_post_content', 'excerpt_on_post', 2 ); 
    function excerpt_on_post() {
        if ( is_single() && has_excerpt() ) {
    	echo '<div class="excerpt-on-post">
    				<p><span class="help">Summary: </span>';
    				$my_excerpt = get_the_excerpt();
    				echo $my_excerpt;
    		echo '</p></div>';
    	}
    }
    

    Thanks for the reply Doak!!


    My two small blogs: NetRival | BlogSynthesis
    unanswerd

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.