3rd party shortcodes not working in Posts Carousel

About this forum
These forums have not been active for several years. They're available for search and reference, but a lot of this information is likely out of date.

For current information, try visiting our Knowledge Base.

Home / Support / Beaver Builder Theme / 3rd party shortcodes not working in Posts Carousel

This topic is: not resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #115106

    Josh
    Participant

    I have an event program that provides shortcodes to populate the date/time of an event. It appears on the event page but doesn’t appear within the Posts Carousel.

    Event – “Monthly Dinner”

    Date/time in red text is generated by shortcode.

    Wasn’t sure if this was the theme, plugin, or wordpress the issue is with. Thanks!

    #115236

    Jun
    Keymaster

    Hey Josh!

    This might be because shortcodes and HTML don’t work with WP excerpt. Haven’t tried it myself by try adding the code below in your functions.php file and see if it helps. You can find your theme function file by going to Appearance > Editor > Theme Functions

    add_filter('the_excerpt', 'do_shortcode');

    Jun

    #115267

    Jun
    Keymaster

    Hey Josh!

    I just tested this and that single line of code will not work. It seems that this is a bit more complex than I originally thought but I found a solution someone posted here. Give it a try and let us know how it goes. You still add this in the functions.php file.

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wp_trim_excerpt_do_shortcode');
    
    function wp_trim_excerpt_do_shortcode($text) {
    	$raw_excerpt = $text;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    
    		$text = do_shortcode( $text ); // CHANGED HERE
    
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    		$excerpt_length = apply_filters('excerpt_length', 55);
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    		if ( count($words) > $excerpt_length ) {
    			array_pop($words);
    			$text = implode(' ', $words);
    			$text = $text . $excerpt_more;
    		} else {
    			$text = implode(' ', $words);
    		}
    	}
    	return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
    }

    Jun

    #115327

    Josh
    Participant

    That did the trick. Excellent. Thanks for digging into that one. Your 2nd post made the difference!

    #115330

    Jun
    Keymaster

    Hey Josh!

    Glad to hear it’s all sorted out now and thanks for taking the time to let us know. We appreciate it!

    Have a nice day!

    Jun

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘Beaver Builder Theme’ is closed to new topics and replies.