<?php if ( ! function_exists( 'pft_custom_limit_words' ) ) : /** * Returns post excerpt. * * @since 1.0.0 * * @param int $length Excerpt length in words. * @param WP_Post $post_object The post object. * @return string Post excerpt. */ function pft_custom_limit_words( $length = 0, $post_object = null ) { global $post; if ( is_null( $post_object ) ) { $post_object = $post; } $length = absint( $length ); if ( 0 === $length ) { return; } $source_content = $post_object->post_content; if ( ! empty( $post_object->post_excerpt ) ) { $source_content = $post_object->post_excerpt; } $source_content = strip_shortcodes( $source_content ); $trimmed_content = wp_trim_words( $source_content, $length, '...' ); return $trimmed_content; } endif;