Hi there,
We have pages that have content between visual composer shortcodes, that look to be being stripped when displaying the excerpt on the grid.
We first looked at the filter to see if we could preserve the content between the tags in this way (which works with other plugins we use):
function post_grid_filter_grid_item_excerpt_extra($excerpt){
return $excerpt = wp_trim_words(wp_strip_all_tags(preg_replace("/\[[^\]]+\]/", '', $excerpt)), 20, '...');
}
add_filter('post_grid_filter_grid_item_excerpt','post_grid_filter_grid_item_excerpt_extra');
Then we looked into the plugin code and changed the following lines (which we don't want to change :), just to see what might be happening but still did not seem to work?
$excerpt_removed_shortcode = preg_replace( '/\[[^\]]+\]/', '', get_the_excerpt());
$item['excerpt_read_more'] = ''.wp_trim_words(preg_replace( "/\[[^\]]+\]/", '', get_the_excerpt()), $char_limit,'').' '.$read_more_text.'';
If there is anything you can do to point us in the right direction to preserve the content between shortcode tags such as with Visual comporser that would be great as we go live in a few days.
Thanks very much!
/** * Filter the excerpt "content" string. * * @param string $text excerpt string. * @return string (Maybe) modified, not stripping out the content between shortcodes, such as with visual composer */ function custom_excerpt($text = '') { $raw_excerpt = $text; if ( '' == $text ) { $text = get_the_content(''); // $text = strip_shortcodes( $text ); $text = do_shortcode( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'get_the_excerpt', 'custom_excerpt' );
