Visual composer content being stripped

0
Visual composer content being stripped 1
Steve
Nov 28, 2017 09:20 AM 1 Answers General
Member Since Nov 2016
Subscribed Subscribe Not subscribe
Flag(0)

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!

1 Subscribers
Visual composer content being stripped 1
Submit Answer
Please login to submit answer.
1 Answers
Sort By:
Best Answer
0
Visual composer content being stripped 3
Steve
May 22, 2018
Flag(0)

Not sure why this was marked as solved, as there was no answer?

For anyone else who has this problem and is looking for an answer, basically, the plugin (correctly depending on what you need, but not what I needed) is calling strip_shortcodes(get_the_excerpt())); in class-functions.php:

$excerpt_removed_shortcode = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', strip_shortcodes(get_the_excerpt()));

If you don't want to edit the plugin directly (not recommended), the option of you want to preserve the content between the shortcode, such as with visual composer, is to add something like this into your functions.php file (credit: @keesiemeijer from https://wordpress.org/support/topic/stripping-shortcodes-keeping-the-content/#post-2770209):

/**
* 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' );

Sign in to Reply
Replying as Submit