// stolen from class-avada-blog.php
// Create an excerpt stripping out avada shortcodes but not the shortcode content
// You will need the content from the post object not just the post id
// i.e. get_post($post_id)->post_content
function get_content_stripped_and_excerpted( $excerpt_length, $content ) {
$pattern = get_shortcode_regex();
$content = preg_replace_callback( "/$pattern/s", 'fusion_extract_shortcode_contents', $content );
$content = explode( ' ', $content, $excerpt_length + 1 );
if ( $excerpt_length < count( $content ) ) {
array_pop( $content );
}
$content = implode( ' ', $content );
$content = preg_replace( '~(?:\[/?)[^/\]]+/?\]~s', '', $content ); // Strip shortcodes and keep the content.
$content = str_replace( ']]>', ']]>', $content );
$content = strip_tags( $content );
$content = str_replace( array( '"', "'" ), array( '"', ''' ), $content );
$content = trim( $content );
return $content;
}