neha4no
8/7/2019 - 12:56 PM

post title excerpt

get_the_excerpt() : this checks whether post has excerpt or not. if no excerpt then it calls post content and on applying wp_trim words we can define word count as well.

<?php 
/**
 * Function to display post excerpt/content with limited words on listing page. calling echo apply_filters('the_content', post_excerpt(20));
 * @global type $post
 * @param type $word_count
 * @return type string
 */
function post_excerpt($word_count = 15) {
   return wp_trim_words(get_the_excerpt(), $word_count);
}

// Changing excerpt more
function post_excerpt_more($more) {
    $more = '...';
    return $more;
}

add_filter('excerpt_more', 'post_excerpt_more');